├── BaiduSearchAdvancedNews.m ├── CalculateStockXRD.m ├── DataResampleClass.m ├── DataResampleTestScript.m ├── Dlog.txt ├── FQuantStudio微信公众号二维码.jpg ├── FQuantTooLBoxV1.2使用注意点整理(by群友 达达@成都).pdf ├── FQuantToolBox Mannual V1.4 byLY_faruto.pdf ├── FQuantToolBox UsedFor.jpg ├── FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx ├── Dlog.txt ├── FQuantStudio微信公众号二维码.jpg ├── FQuantToolBox Mannual V1.3 byLY_faruto.pdf ├── FQuantToolBox UsedFor.jpg ├── FQuantToolBoxFileDemo.jpg ├── GetIndexList_Web.m ├── GetIndexTSDay_Web.m ├── GetStockList_Web.m ├── GetStockTSDay_Web.m ├── KplotNew.m ├── LabelSet.m ├── Main_GetFuturesDataTest.m ├── Main_GetStockDataTest.m ├── Main_SaveFuturesData2Local.m ├── Main_SaveStockData2LocalTest.m ├── ReadMe_FQuantToolBox.txt ├── ReadMe_QuantUsingMatlab.txt ├── TickLabelRotate.m ├── matrixplot.m └── 《量化投资:以MATLAB为工具》书籍源码&数据下载二维码.png ├── FQuantToolBoxHelpOnLine V1.4 byLY_faruto.pdf ├── FQuantToolBoxHelpOnLine.m ├── FQuantToolBox下载二维码.png ├── FQuantToolBox使用手册精灵宽客二次整理版本(by群友 SmurfQuant宝山)2015.01.15.pdf ├── Fmatrixplot.m ├── GetBasicInfo_Mat.m ├── GetFutureDay_Web.m ├── GetFutureVolOIRanking_Web.m ├── GetIndexList_Web.m ├── GetIndexTSDay_Web.m ├── GetStock3Sheet_Web.m ├── GetStockFinIndicators_Web.m ├── GetStockInfo_Web.m ├── GetStockInvestRInfo_Web.m ├── GetStockList_Web.m ├── GetStockNotice_Web.m ├── GetStockReport_Web.m ├── GetStockTSDay_Web.m ├── GetStockTick_Web.m ├── GetStockXRD_Web.m ├── GetTableFromWeb.m ├── IndexList.mat ├── JSON.m ├── KplotNew.m ├── LabelSet.m ├── Main_GetFuturesDataTest.m ├── Main_GetStockDataTest.m ├── Main_MatlabSendMailTest.m ├── Main_SaveFuturesData2Local.m ├── Main_SaveStockData2LocalTest.m ├── MatlabSendMailGeneral.m ├── Matlab_sublime(by群友 静看沉浮@大连)2015.04.09.sublime-package ├── Mcode2Pcode.m ├── README.md ├── ReadMe_FQuantToolBox.txt ├── ReadMe_FQuantToolBox全部源码Mcode获取方式.txt ├── ReadMe_QuantUsingMatlab.txt ├── ResampleTestData.mat ├── SaveData2File.m ├── SaveFuturesDay.m ├── SaveFuturesVolOIRankingData.m ├── SaveIndexTSDay.m ├── SaveStockFD.m ├── SaveStockInfo.m ├── SaveStockInvestorRelationsInfo.m ├── SaveStockNotice.m ├── SaveStockTSDay.m ├── SaveStockTick.m ├── SimpleMomentumPortfolioTest.m ├── SinaSearchAdvanced.m ├── StockDataCellTestRaw.mat ├── StockList.mat ├── StockList.txt ├── TickLabelRotate.m ├── URLHexCode2Unicode.m ├── Unicode2URLHexCode.m ├── Unicode2URLHexCode_Ch.m ├── fGetFund.m ├── fGetFundTestScript.m ├── fGetFutrues.m ├── fGetFutruesTestScript.m ├── fGetHKstock.m ├── fGetHKstockTestScript.m ├── fGetIndex.m ├── fGetIndexTestScript.m ├── fGetRTQuotes.m ├── fGetRTQuotesTestScript.m ├── fGetUSstock.m ├── fGetUSstockTestScript.m ├── faruto.matlabsky.com.txt ├── http_createHeader.m ├── http_paramsToString.m ├── isChineseChar.m ├── matrixplot.m ├── urlread2.m ├── urlread_General.m ├── urlreadwrite_General.m ├── urlwrite_General.m └── 《量化投资:以MATLAB为工具》书籍源码&数据下载二维码.png /BaiduSearchAdvancedNews.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/BaiduSearchAdvancedNews.m -------------------------------------------------------------------------------- /CalculateStockXRD.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/CalculateStockXRD.m -------------------------------------------------------------------------------- /DataResampleClass.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/DataResampleClass.m -------------------------------------------------------------------------------- /DataResampleTestScript.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/DataResampleTestScript.m -------------------------------------------------------------------------------- /Dlog.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/Dlog.txt -------------------------------------------------------------------------------- /FQuantStudio微信公众号二维码.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantStudio微信公众号二维码.jpg -------------------------------------------------------------------------------- /FQuantTooLBoxV1.2使用注意点整理(by群友 达达@成都).pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantTooLBoxV1.2使用注意点整理(by群友 达达@成都).pdf -------------------------------------------------------------------------------- /FQuantToolBox Mannual V1.4 byLY_faruto.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox Mannual V1.4 byLY_faruto.pdf -------------------------------------------------------------------------------- /FQuantToolBox UsedFor.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox UsedFor.jpg -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/Dlog.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/Dlog.txt -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/FQuantStudio微信公众号二维码.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/FQuantStudio微信公众号二维码.jpg -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/FQuantToolBox Mannual V1.3 byLY_faruto.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/FQuantToolBox Mannual V1.3 byLY_faruto.pdf -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/FQuantToolBox UsedFor.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/FQuantToolBox UsedFor.jpg -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/FQuantToolBoxFileDemo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/FQuantToolBoxFileDemo.jpg -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/GetIndexList_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/GetIndexList_Web.m -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/GetIndexTSDay_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/GetIndexTSDay_Web.m -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/GetStockList_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/GetStockList_Web.m -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/GetStockTSDay_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/GetStockTSDay_Web.m -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/KplotNew.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/KplotNew.m -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/LabelSet.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/LabelSet.m -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/Main_GetFuturesDataTest.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/Main_GetFuturesDataTest.m -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/Main_GetStockDataTest.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/Main_GetStockDataTest.m -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/Main_SaveFuturesData2Local.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/Main_SaveFuturesData2Local.m -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/Main_SaveStockData2LocalTest.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/Main_SaveStockData2LocalTest.m -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/ReadMe_FQuantToolBox.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/ReadMe_FQuantToolBox.txt -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/ReadMe_QuantUsingMatlab.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/ReadMe_QuantUsingMatlab.txt -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/TickLabelRotate.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/TickLabelRotate.m -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/matrixplot.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/matrixplot.m -------------------------------------------------------------------------------- /FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/《量化投资:以MATLAB为工具》书籍源码&数据下载二维码.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox V1.3[NoHistData] byLY_faruto_FileEx/《量化投资:以MATLAB为工具》书籍源码&数据下载二维码.png -------------------------------------------------------------------------------- /FQuantToolBoxHelpOnLine V1.4 byLY_faruto.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBoxHelpOnLine V1.4 byLY_faruto.pdf -------------------------------------------------------------------------------- /FQuantToolBoxHelpOnLine.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBoxHelpOnLine.m -------------------------------------------------------------------------------- /FQuantToolBox下载二维码.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox下载二维码.png -------------------------------------------------------------------------------- /FQuantToolBox使用手册精灵宽客二次整理版本(by群友 SmurfQuant宝山)2015.01.15.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/FQuantToolBox使用手册精灵宽客二次整理版本(by群友 SmurfQuant宝山)2015.01.15.pdf -------------------------------------------------------------------------------- /Fmatrixplot.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/Fmatrixplot.m -------------------------------------------------------------------------------- /GetBasicInfo_Mat.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/GetBasicInfo_Mat.m -------------------------------------------------------------------------------- /GetFutureDay_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/GetFutureDay_Web.m -------------------------------------------------------------------------------- /GetFutureVolOIRanking_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/GetFutureVolOIRanking_Web.m -------------------------------------------------------------------------------- /GetIndexList_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/GetIndexList_Web.m -------------------------------------------------------------------------------- /GetIndexTSDay_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/GetIndexTSDay_Web.m -------------------------------------------------------------------------------- /GetStock3Sheet_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/GetStock3Sheet_Web.m -------------------------------------------------------------------------------- /GetStockFinIndicators_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/GetStockFinIndicators_Web.m -------------------------------------------------------------------------------- /GetStockInfo_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/GetStockInfo_Web.m -------------------------------------------------------------------------------- /GetStockInvestRInfo_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/GetStockInvestRInfo_Web.m -------------------------------------------------------------------------------- /GetStockList_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/GetStockList_Web.m -------------------------------------------------------------------------------- /GetStockNotice_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/GetStockNotice_Web.m -------------------------------------------------------------------------------- /GetStockReport_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/GetStockReport_Web.m -------------------------------------------------------------------------------- /GetStockTSDay_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/GetStockTSDay_Web.m -------------------------------------------------------------------------------- /GetStockTick_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/GetStockTick_Web.m -------------------------------------------------------------------------------- /GetStockXRD_Web.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/GetStockXRD_Web.m -------------------------------------------------------------------------------- /GetTableFromWeb.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/GetTableFromWeb.m -------------------------------------------------------------------------------- /IndexList.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/IndexList.mat -------------------------------------------------------------------------------- /JSON.m: -------------------------------------------------------------------------------- 1 | classdef JSON < handle 2 | % v = JSON.parse(jsonString) converts a JSON string to a MATLAB value. 3 | % 4 | % This started out as a recursive descent parser, but JSON is so simple 5 | % that most of the parser collapsed out. 6 | % 7 | % In the service of speed, simplicity, and laziness, this code is NOT a 8 | % validator. Its purpose is to convert correct JSON strings to MATLAB 9 | % values. It does not reject all malformed JSON. 10 | 11 | % Copyright 2013 The MathWorks, Inc. 12 | 13 | properties (Access = private) 14 | json % the string 15 | index % position in the string 16 | end 17 | 18 | 19 | methods (Access = private) 20 | 21 | function this = JSON(JSONstring) 22 | this.json = JSONstring; 23 | this.index = 1; 24 | end 25 | 26 | function value = getValue(this) 27 | % get the next value in the string 28 | [token,tokenType] = this.getNextToken; 29 | value = token; 30 | 31 | if strcmp(tokenType,'Special') 32 | if strcmp(token,'{') 33 | value = this.getObject; 34 | elseif strcmp(token,'[') 35 | value = this.getArray; 36 | end 37 | end 38 | end 39 | 40 | function array = getArray(this) 41 | % an array is [ value, ... ] 42 | array = {}; 43 | 44 | value = this.getValue; 45 | while ~strcmp(value,']') 46 | % got a value 47 | array{end+1} = value; %#ok final size is unknowable 48 | 49 | % followed by a comma or a "]" 50 | value = this.getValue; 51 | 52 | if strcmp(value,',') 53 | value = this.getValue; 54 | elseif strcmp(value,']') 55 | continue 56 | else 57 | error('JSON parser requires commas between array elements'); 58 | end 59 | end 60 | 61 | % Arrays of all numbers are turned into numeric arrays 62 | fcn = @(x) isnumeric(x) && ~isscalar(x); 63 | if all(cellfun(fcn,array)) 64 | array = [array{:}]; 65 | end 66 | end 67 | 68 | function obj = getObject(this) 69 | % an object is { string : value, ... } 70 | obj = struct; 71 | value = this.getValue; 72 | while ~strcmp(value,'}') 73 | 74 | fieldname = value; 75 | % make sure its a valid structure field name 76 | fieldname = strrep(fieldname,':','_'); 77 | fieldname = strrep(fieldname,'-','_'); 78 | % fix for field names that start with numbers 79 | % Thanks to Guy Ziv! 80 | fieldname = regexprep(fieldname,'(^\d)','s$1'); 81 | 82 | % check for colon 83 | value = this.getValue; 84 | if ~strcmp(value,':') 85 | error('JSON parser requires colons between object names and values'); 86 | end 87 | 88 | % get the value 89 | value = this.getValue; 90 | obj.(fieldname) = value; 91 | 92 | value = this.getValue; 93 | if strcmp(value,',') 94 | value = this.getValue; 95 | elseif strcmp(value,'}') 96 | continue 97 | else 98 | error('JSON parser requires commas between object elements'); 99 | end 100 | end 101 | 102 | end 103 | 104 | function [token,tokenType] = getNextToken(this) 105 | % get whatever is next in the string 106 | 107 | % skip whitespace 108 | ch = this.json(this.index); 109 | while isWhitespace(ch) 110 | this.index = this.index + 1; 111 | ch = this.json(this.index); 112 | end 113 | 114 | % is it a special character? 115 | if isSpecial(ch) 116 | token = ch; 117 | tokenType = 'Special'; 118 | this.index = this.index + 1; 119 | return 120 | end 121 | 122 | % is it one of the three keywords? 123 | switch(ch) 124 | case 't' 125 | match(this,'true'); 126 | token = true; 127 | tokenType = 'Logical'; 128 | return; 129 | case 'f' 130 | match(this,'false'); 131 | tokenType = 'Logical'; 132 | token = false; 133 | return; 134 | case 'n' 135 | match(this,'null'); 136 | tokenType = 'Null'; 137 | token = []; 138 | return; 139 | end 140 | 141 | % is it a string? 142 | if(ch == '"') 143 | token = getString(this); 144 | tokenType = 'String'; 145 | return; 146 | end 147 | 148 | % well, then it better be a number 149 | token = getNumber(this); 150 | tokenType = 'Number'; 151 | 152 | function match(this,str) 153 | % find and consume exactly str at the current location of error 154 | n = length(str); 155 | range = this.index:(this.index + n - 1); 156 | found = this.json(range); 157 | if strcmp(str,found) 158 | this.index = this.index + n; 159 | else 160 | error('The JSON parser expected "%s" but found %s',str,found) 161 | end 162 | end 163 | 164 | function tf = isWhitespace(aChar) 165 | % space, carrage return, linefeed, horizontal tab 166 | tf = aChar == 32 || aChar == 10 || aChar == 13 || aChar == 9; 167 | end 168 | 169 | function tf = isSpecial(aChar) 170 | % the special characters in the JSON "language" 171 | tf = aChar == '{' || aChar == '}' || aChar == '['|| aChar == ']'|| aChar == ':' || aChar == ','; 172 | end 173 | 174 | function string = getString(this) 175 | first = this.index + 1; 176 | last = first; 177 | str = this.json; 178 | 179 | ch = str(last); 180 | while ch ~= '"' 181 | if(ch == '\\') %#ok We KNOW both are single chars 182 | last = last + 2; 183 | else 184 | last = last + 1; 185 | end 186 | ch = str(last); 187 | end 188 | 189 | % get the string without it's quotes 190 | string = str(first:(last-1)); 191 | this.index = last + 1; % skip the trailing " 192 | end 193 | 194 | function number = getNumber(this) 195 | first = this.index; 196 | last = first; 197 | ch = charAt(this,first); 198 | 199 | if(ch == '-') 200 | last = last + 1; 201 | ch = charAt(this,last); 202 | end 203 | 204 | while isDigit(ch) 205 | last = last + 1; 206 | ch = charAt(this,last); 207 | end 208 | 209 | if(ch == '.') 210 | last = last + 1; 211 | ch = charAt(this,last); 212 | while isDigit(ch) 213 | last = last + 1; 214 | ch = charAt(this,last); 215 | end 216 | end 217 | 218 | if ch == 'e' || ch == 'E' 219 | last = last + 1; 220 | ch = charAt(this,last); 221 | if ismember(ch,'+-') 222 | last = last + 1; 223 | ch = charAt(this,last); 224 | end 225 | while isDigit(ch) 226 | last = last + 1; 227 | ch = charAt(this,last); 228 | end 229 | end 230 | 231 | % pull out the string 232 | str = this.json(first:(last-1)); 233 | number = str2double(str); 234 | 235 | % move past it 236 | this.index = last; 237 | 238 | % helper functions 239 | function char = charAt(this,position) 240 | if(position > length(this.json)) 241 | char = 0; 242 | else 243 | char = this.json(position); 244 | end 245 | end 246 | 247 | function tf = isDigit(aChar) 248 | tf = aChar > 47 && aChar < 58; 249 | end 250 | 251 | end 252 | 253 | end 254 | 255 | end 256 | 257 | methods(Static) 258 | % This is the one method you should call from outside the file. 259 | % JSON.parse(string)... that should be familiar to Javascrpt 260 | % programmers 261 | function value = parse(JSONstring) 262 | jsonObject = JSON(JSONstring); 263 | value = jsonObject.getValue; 264 | end 265 | end 266 | 267 | end -------------------------------------------------------------------------------- /KplotNew.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/KplotNew.m -------------------------------------------------------------------------------- /LabelSet.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/LabelSet.m -------------------------------------------------------------------------------- /Main_GetFuturesDataTest.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/Main_GetFuturesDataTest.m -------------------------------------------------------------------------------- /Main_GetStockDataTest.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/Main_GetStockDataTest.m -------------------------------------------------------------------------------- /Main_MatlabSendMailTest.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/Main_MatlabSendMailTest.m -------------------------------------------------------------------------------- /Main_SaveFuturesData2Local.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/Main_SaveFuturesData2Local.m -------------------------------------------------------------------------------- /Main_SaveStockData2LocalTest.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/Main_SaveStockData2LocalTest.m -------------------------------------------------------------------------------- /MatlabSendMailGeneral.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/MatlabSendMailGeneral.m -------------------------------------------------------------------------------- /Matlab_sublime(by群友 静看沉浮@大连)2015.04.09.sublime-package: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/Matlab_sublime(by群友 静看沉浮@大连)2015.04.09.sublime-package -------------------------------------------------------------------------------- /Mcode2Pcode.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/Mcode2Pcode.m -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FQuantToolBox 2 | FQuantToolBox 3 | 4 | FQuantToolBox全部源码Mcode公开-20181130 by faruto 5 | 6 | more info see http://faruto.matlabsky.com/ 7 | 8 | ============================================================= 9 | 10 | more info see http://www.matlabsky.com/forum-112-1.html 11 | 12 | 工具箱的使用请详见里面的mannual :FQuantToolBox Mannual V1.3 byLY_faruto.pdf 13 | 14 | ========================================================================== 15 | FQuantToolBox by 李洋faruto 16 | 17 | http://weibo.com/faruto 18 | 19 | http://www.matlabsky.com 20 | 21 | http://blog.sina.com.cn/faruto 22 | 23 | Email:farutoliyang@foxmail.com 24 | 25 | FQuantToolBox: A Data and Backtesting Quant Tool Box based on MATLAB by faruto. 26 | 27 | Version: V1.3 28 | Last Modified 2015.01.24 29 | 30 | ================================= 31 | History: 32 | 33 | V1.3 2015.01.24 34 | 35 | V1.2 2015.01.01 36 | 37 | V1.1 2014.12.18 38 | 39 | V1.0 2014.12.12 40 | 41 | ================================= 42 | 43 | What for? 44 | 45 | ================================= 46 | FQuantToolBox是做什么用的? 47 | FQuantToolBox定位是个数据和回测工具箱,没有实盘交易相关接口的实现(但未来不排除增加相关功能)。 48 | 数据方面,FQuantToolBox数据获取函数完全基于网络的免费数据源(主要为新浪财经、雅虎财经等金融网站),不但可以积累历史数据,也可以进行动态更新,现已实现的数据获取为A股市场的全部股票名称和对应代码(包含已退市股票)、A股市场的股票日线除权数据以及复权因子、A股市场的股票的除权除息信息、A股市场的股票每日交易明细数据(Tick数据)、A股市场的的股票财务指标数据、A股市场的股票的三张表(资产负债表、现金流量表、利润表)数据,未来数据方面会增加更多的数据,包括期货数据以及其他金融标的的数据,整体的思想还是完全基于网络获取和更新,完全免费。 49 | 基于网络的数据获取的实现方式大体过程就是网络数据网址寻找——> 网址分析——> urlread+正则表达式 数据提取。进行网络数据的抓取,正则表达式是一定会遇到的,MATLAB中有相应的正则表达式函数,有关正则表达式的东西这里不做展开,各位看官需要自行做些功课,FQuantToolBox工具箱的Doc文件夹内有个我重新整理过的《MATALB正则表达式零基础起步教程.doc》文档,可以帮助您学习正则表达式相关的东西。 50 | 回测方面,FQuantToolBox工具箱当下提供了一个“如何构建基于MATLAB的回测系统”的demo样例,此部分内容来自我出版的《量化投资:以MATLAB为工具》的相关章节,未来回测方面会增添更多的辅助函数和插件,方便您使用MATLAB进行股票以及期货相关策略的回测。 51 | 未来FQuantToolBox工具箱每次发布都会提供两个版本,无历史数据版本和有历史数据版本。无历史数据版本仅提供相关函数,你可以在自己本地运行相关脚本来批量获取历史数据;有历史数据版本不但提供相关函数,还提供已经获取好的历史数据(A股市场全部股票股票名称和代码、日线数据、每日交易明细数据、除权除息信息、财务指标数据、三张变数据),节省您获取历史数据的时间,但相应的下载文件也会比较大(尤其股票每日交易明细数据),新的数据更新只需运行相应脚本函数就可以进行全市场最新数据的更新。 52 | 53 | ================================= 54 | 55 | V1.3主要更新为: 56 | 57 | 更新优化调整了部分核心代码,提高代码运行速度。 58 | 59 | ================================= 60 | V1.2更新说明 61 | 62 | FQuantToolBox V1.2主要更新为: 63 | 64 | 增加获取上海证券交易所和深圳证券交易所相关指数数据,包括指数代码和名称列表、指数从基期到最新日期的日线数据; 65 | 增加获取上市公司公告文件列表数据,以及保存相应文件至本地,基于此类数据可以开发event-driven类模型; 66 | 增加获取上市公司投资者关系信息(Investor Relations Info)列表数据,以及保存相应文件至本地,基于此类数据可以开发event-driven类模型; 67 | 数据批量保存函数中的函数读取方式更新为采用matfile函数实现(而非之前的load方式实现),提高数量批量保存效率。 68 | 增加获取百度高级搜索相关内容,可以任意指定个股相关关键词,获取搜索之后的相关词条的时间、来源、URL链接等内容,且可以指定搜索时间段; 69 | 增加获取新浪高级搜索相关内容,可以任意指定个股相关关键词,获取搜索之后的相关词条的时间、来源、URL链接等内容,且可以指定搜索时间段。 70 | 71 | ================================= 72 | 73 | V1.1更新说明 74 | FQuantToolBoxV1.1主要更新为 75 | 76 | 增加个股公司基本介绍信息、个股证监会分类和所属概念分类;增加期货合约日线数据、增加期货合约每日成交量持仓量排名数据。 77 | 78 | ================================= 79 | -------------------------------------------------------------------------------- /ReadMe_FQuantToolBox.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/ReadMe_FQuantToolBox.txt -------------------------------------------------------------------------------- /ReadMe_FQuantToolBox全部源码Mcode获取方式.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/ReadMe_FQuantToolBox全部源码Mcode获取方式.txt -------------------------------------------------------------------------------- /ReadMe_QuantUsingMatlab.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/ReadMe_QuantUsingMatlab.txt -------------------------------------------------------------------------------- /ResampleTestData.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/ResampleTestData.mat -------------------------------------------------------------------------------- /SaveData2File.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/SaveData2File.m -------------------------------------------------------------------------------- /SaveFuturesDay.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/SaveFuturesDay.m -------------------------------------------------------------------------------- /SaveFuturesVolOIRankingData.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/SaveFuturesVolOIRankingData.m -------------------------------------------------------------------------------- /SaveIndexTSDay.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/SaveIndexTSDay.m -------------------------------------------------------------------------------- /SaveStockFD.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/SaveStockFD.m -------------------------------------------------------------------------------- /SaveStockInfo.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/SaveStockInfo.m -------------------------------------------------------------------------------- /SaveStockInvestorRelationsInfo.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/SaveStockInvestorRelationsInfo.m -------------------------------------------------------------------------------- /SaveStockNotice.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/SaveStockNotice.m -------------------------------------------------------------------------------- /SaveStockTSDay.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/SaveStockTSDay.m -------------------------------------------------------------------------------- /SaveStockTick.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/SaveStockTick.m -------------------------------------------------------------------------------- /SimpleMomentumPortfolioTest.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/SimpleMomentumPortfolioTest.m -------------------------------------------------------------------------------- /SinaSearchAdvanced.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/SinaSearchAdvanced.m -------------------------------------------------------------------------------- /StockDataCellTestRaw.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/StockDataCellTestRaw.mat -------------------------------------------------------------------------------- /StockList.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/StockList.mat -------------------------------------------------------------------------------- /StockList.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/StockList.txt -------------------------------------------------------------------------------- /TickLabelRotate.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/TickLabelRotate.m -------------------------------------------------------------------------------- /URLHexCode2Unicode.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/URLHexCode2Unicode.m -------------------------------------------------------------------------------- /Unicode2URLHexCode.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/Unicode2URLHexCode.m -------------------------------------------------------------------------------- /Unicode2URLHexCode_Ch.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/Unicode2URLHexCode_Ch.m -------------------------------------------------------------------------------- /fGetFund.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/fGetFund.m -------------------------------------------------------------------------------- /fGetFundTestScript.m: -------------------------------------------------------------------------------- 1 | %% fGetFundTestScript 2 | % by LiYang_faruto 3 | % Email:farutoliyang@foxmail.com 4 | % 2015/06/01 5 | 6 | %% A Little Clean Work 7 | tic; 8 | % clear; 9 | % clc; 10 | % close all; 11 | format compact; 12 | %% 13 | 14 | GetFund = fGetFund(); 15 | 16 | GetFund.Code = '510050'; 17 | 18 | GetFund.StartDate = 'All'; 19 | GetFund.StartDate = '20150101'; 20 | GetFund.EndDate = datestr(today,'yyyymmdd'); 21 | 22 | GetFund.isSave = 0; 23 | 24 | %% 25 | tic; 26 | 27 | [OutputData,Headers] = GetFund.GetNetValue(); 28 | 29 | toc; 30 | %% 31 | tic; 32 | 33 | [OutputData] = GetFund.GetFundProfile(); 34 | 35 | toc; 36 | %% 37 | tic; 38 | 39 | GetFund.StartDate = 'All'; 40 | % GetFund.StartDate = '20150101'; 41 | GetFund.EndDate = datestr(today,'yyyymmdd'); 42 | 43 | [OutputData,Headers] = GetFund.GetFundShareChg(); 44 | 45 | toc; 46 | %% 47 | 48 | 49 | 50 | 51 | %% Record Time 52 | toc; 53 | displayEndOfDemoMessage(mfilename); 54 | -------------------------------------------------------------------------------- /fGetFutrues.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/fGetFutrues.m -------------------------------------------------------------------------------- /fGetFutruesTestScript.m: -------------------------------------------------------------------------------- 1 | %% fGetFutruesTestScript 2 | % by LiYang_faruto 3 | % Email:farutoliyang@foxmail.com 4 | % 2015/06/01 5 | %% A Little Clean Work 6 | tic; 7 | % clear; 8 | % clc; 9 | % close all; 10 | format compact; 11 | %% 12 | 13 | GetFutrues = fGetFutrues(); 14 | GetFutrues.isPlot = 1; 15 | GetFutrues.isSave = 0; 16 | GetFutrues.isTicToc = 1; 17 | 18 | %% 19 | 20 | 21 | OutputData = GetFutrues.GetHotMonth(); 22 | 23 | 24 | %% 25 | 26 | %% Record Time 27 | toc; 28 | displayEndOfDemoMessage(mfilename); -------------------------------------------------------------------------------- /fGetHKstock.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/fGetHKstock.m -------------------------------------------------------------------------------- /fGetHKstockTestScript.m: -------------------------------------------------------------------------------- 1 | %% fGetHKstockTestScript 2 | % by LiYang_faruto 3 | % Email:farutoliyang@foxmail.com 4 | % 2015/06/01 5 | %% A Little Clean Work 6 | tic; 7 | % clear; 8 | % clc; 9 | % close all; 10 | format compact; 11 | %% 12 | 13 | GetHKstock = fGetHKstock(); 14 | 15 | GetHKstock.Code = '00700'; 16 | 17 | GetHKstock.StartDate = 'All'; 18 | GetHKstock.EndDate = datestr(today,'yyyymmdd'); 19 | 20 | GetHKstock.isSave = 1; 21 | GetHKstock.isPlot = 1; 22 | %% 23 | tic; 24 | OutputData = GetHKstock.GetList(); 25 | toc; 26 | 27 | %% 28 | 29 | GetHKstock.StartDate = '20150101'; 30 | GetHKstock.EndDate = datestr(today,'yyyymmdd'); 31 | % GetHKstock.EndDate = '20150501'; 32 | 33 | tic; 34 | 35 | [OutputData,Headers] = GetHKstock.GetPrice(); 36 | 37 | toc; 38 | %% 39 | 40 | [OutputData] = GetHKstock.GetProfile(); 41 | %% 42 | 43 | [OutputData] = GetHKstock.GetDividends(); 44 | 45 | 46 | %% 47 | 48 | %% Record Time 49 | toc; 50 | displayEndOfDemoMessage(mfilename); 51 | -------------------------------------------------------------------------------- /fGetIndex.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/fGetIndex.m -------------------------------------------------------------------------------- /fGetIndexTestScript.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/fGetIndexTestScript.m -------------------------------------------------------------------------------- /fGetRTQuotes.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/fGetRTQuotes.m -------------------------------------------------------------------------------- /fGetRTQuotesTestScript.m: -------------------------------------------------------------------------------- 1 | %% fGetRTQuotesTestScript 2 | % by LiYang_faruto 3 | % Email:farutoliyang@foxmail.com 4 | % 2015/06/01 5 | 6 | %% A Little Clean Work 7 | tic; 8 | % clear; 9 | % clc; 10 | % close all; 11 | format compact; 12 | %% 13 | 14 | GetRTQuotes = fGetRTQuotes(); 15 | 16 | GetRTQuotes.Code = {'600036';'M0';'IF1506';'150197';'TA0';'RB0';'510050'}; 17 | 18 | DataCell = GetRTQuotes.GetRTQuotes(); 19 | 20 | %% 21 | 22 | %% Record Time 23 | toc; 24 | displayEndOfDemoMessage(mfilename); 25 | -------------------------------------------------------------------------------- /fGetUSstock.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/fGetUSstock.m -------------------------------------------------------------------------------- /fGetUSstockTestScript.m: -------------------------------------------------------------------------------- 1 | %% fGetUSstockTestScript 2 | % by LiYang_faruto 3 | % Email:farutoliyang@foxmail.com 4 | % 2015/06/01 5 | 6 | %% A Little Clean Work 7 | tic; 8 | % clear; 9 | % clc; 10 | % close all; 11 | format compact; 12 | %% 13 | 14 | GetUSstock = fGetUSstock(); 15 | 16 | GetUSstock.Code = 'AAPL'; 17 | % GetUSstock.Code = 'MSFT'; 18 | % GetUSstock.Code = 'IXIC'; 19 | 20 | GetUSstock.StartDate = 'All'; 21 | GetUSstock.StartDate = '20150101'; 22 | GetUSstock.EndDate = datestr(today,'yyyymmdd'); 23 | 24 | GetUSstock.ListSource = 'sina'; 25 | GetUSstock.ListSource = 'ifeng'; 26 | 27 | GetUSstock.isSave = 1; 28 | GetUSstock.isPlot = 1; 29 | GetUSstock.isTicToc = 1; 30 | %% 31 | 32 | GetUSstock.StartDate = '20140101'; 33 | [OutputData,Headers] = GetUSstock.GetHistQuote(); 34 | Headers 35 | %% 36 | tic; 37 | OutputData = GetUSstock.GetList(); 38 | toc; 39 | %% 40 | 41 | [OutputData,Headers] = GetUSstock.GetDividends(); 42 | Headers 43 | 44 | %% 45 | %% Record Time 46 | toc; 47 | displayEndOfDemoMessage(mfilename); 48 | -------------------------------------------------------------------------------- /faruto.matlabsky.com.txt: -------------------------------------------------------------------------------- 1 | 欢迎访问 2 | 3 | http://faruto.matlabsky.com/ 4 | 5 | http://faruto.matlabsky.com/FQuantToolBoxHelpOnLine/ -------------------------------------------------------------------------------- /http_createHeader.m: -------------------------------------------------------------------------------- 1 | function header = http_createHeader(name,value) 2 | %http_createHeader Simple function for creating input header to urlread2 3 | % 4 | % header = http_createHeader(name,value) 5 | % 6 | % CODE: header = struct('name',name,'value',value); 7 | % 8 | % See Also: 9 | % urlread2 10 | 11 | header = struct('name',name,'value',value); -------------------------------------------------------------------------------- /http_paramsToString.m: -------------------------------------------------------------------------------- 1 | function [str,header] = http_paramsToString(params,encodeOption) 2 | %http_paramsToString Creates string for a POST or GET requests 3 | % 4 | % [queryString,header] = http_paramsToString(params, *encodeOption) 5 | % 6 | % INPUTS 7 | % ======================================================================= 8 | % params: cell array of property/value pairs 9 | % NOTE: If the input is in a 2 column matrix, then first column 10 | % entries are properties and the second column entries are 11 | % values, however this is NOT necessary (generally linear) 12 | % encodeOption: (default 1) 13 | % 1 - the typical URL encoding scheme (Java call) 14 | % 15 | % OUTPUTS 16 | % ======================================================================= 17 | % queryString: querystring to add onto URL (LACKS "?", see example) 18 | % header : the header that should be attached for post requests when 19 | % using urlread2 20 | % 21 | % EXAMPLE: 22 | % ============================================================== 23 | % params = {'cmd' 'search' 'db' 'pubmed' 'term' 'wtf batman'}; 24 | % queryString = http_paramsToString(params); 25 | % queryString => cmd=search&db=pubmed&term=wtf+batman 26 | % 27 | % IMPORTANT: This function does not filter parameters, sort them, 28 | % or remove empty inputs (if necessary), this must be done before hand 29 | 30 | if ~exist('encodeOption','var') 31 | encodeOption = 1; 32 | end 33 | 34 | if size(params,2) == 2 && size(params,1) > 1 35 | params = params'; 36 | params = params(:); 37 | end 38 | 39 | str = ''; 40 | for i=1:2:length(params) 41 | if (i == 1), separator = ''; else separator = '&'; end 42 | switch encodeOption 43 | case 1 44 | param = urlencode(params{i}); 45 | value = urlencode(params{i+1}); 46 | % case 2 47 | % param = oauth.percentEncodeString(params{i}); 48 | % value = oauth.percentEncodeString(params{i+1}); 49 | % header = http_getContentTypeHeader(1); 50 | otherwise 51 | error('Case not used') 52 | end 53 | str = [str separator param '=' value]; %#ok 54 | end 55 | 56 | switch encodeOption 57 | case 1 58 | header = http_createHeader('Content-Type','application/x-www-form-urlencoded'); 59 | end 60 | 61 | 62 | end -------------------------------------------------------------------------------- /isChineseChar.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/isChineseChar.m -------------------------------------------------------------------------------- /matrixplot.m: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/matrixplot.m -------------------------------------------------------------------------------- /urlread2.m: -------------------------------------------------------------------------------- 1 | function [output,extras] = urlread2(urlChar,method,body,headersIn,varargin) 2 | %urlread2 Makes HTTP requests and processes response 3 | % 4 | % [output,extras] = urlread2(urlChar, *method, *body, *headersIn, varargin) 5 | % 6 | % * indicates optional inputs that must be entered in place 7 | % 8 | % UNDOCUMENTED MATLAB VERSION 9 | % 10 | % EXAMPLE CALLING FORMS 11 | % ... = urlread2(urlChar) 12 | % ... = urlread2(urlChar,'GET','',[],prop1,value1,prop2,value2,etc) 13 | % ... = urlread2(urlChar,'POST',body,headers) 14 | % 15 | % FEATURES 16 | % ======================================================================= 17 | % 1) Allows specification of any HTTP method 18 | % 2) Allows specification of any header. Very little is hard-coded 19 | % in for header handling. 20 | % 3) Returns response status and headers 21 | % 4) Should handle unicode properly ... 22 | % 23 | % OUTPUTS 24 | % ======================================================================= 25 | % output : body of the response, either text or binary depending upon 26 | % CAST_OUTPUT property 27 | % extras : (structure) 28 | % .allHeaders - stucture, fields have cellstr values, HTTP headers may 29 | % may be repeated but will have a single field entry, with each 30 | % repeat's value another being another entry in the cellstr, for 31 | % example: 32 | % .Set_Cookie = {'first_value' 'second_value'} 33 | % .firstHeaders - (structure), variable fields, contains the first 34 | % string entry for each field in allHeaders, this 35 | % structure can be used to avoid dereferencing a cell 36 | % for fields you expect not to be repeated ... 37 | % EXAMPLE: 38 | % .Response : 'HTTP/1.1 200 OK'} 39 | % .Server : 'nginx' 40 | % .Date : 'Tue, 29 Nov 2011 02:23:16 GMT' 41 | % .Content_Type : 'text/html; charset=UTF-8' 42 | % .Content_Length : '109155' 43 | % .Connection : 'keep-alive' 44 | % .Vary : 'Accept-Encoding, User-Agent' 45 | % .Cache_Control : 'max-age=60, private' 46 | % .Set_Cookie : 'first_value' 47 | % .status - (structure) 48 | % .value : numeric value of status, ex. 200 49 | % .msg : message that goes along with status, ex. 'OK' 50 | % .url - eventual url that led to output, this can change from 51 | % the input with redirects, see FOLLOW_REDIRECTS 52 | % .isGood - (logical) I believe this is an indicator of the presence of 400 53 | % or 500 status codes (see status.value) but more 54 | % testing is needed. In other words, true if status.value < 400. 55 | % In code, set true if the response was obtainable without 56 | % resorting to checking the error stream. 57 | % 58 | % INPUTS 59 | % ======================================================================= 60 | % urlChar : The full url, must include scheme (http, https) 61 | % method : examples: 'GET' 'POST' etc 62 | % body : (vector)(char, uint8 or int8) body to write, generally used 63 | % with POST or PUT, use of uint8 or int8 ensures that the 64 | % body input is not manipulated before sending, char is sent 65 | % via unicode2native function with ENCODING input (see below) 66 | % headersIn : (structure array), use empty [] or '' if no headers are needed 67 | % but varargin property/value pairs are, multiple headers 68 | % may be passed in as a structure array 69 | % .name - (string), name of the header, a name property is used 70 | % instead of a field because the name must match a valid 71 | % header 72 | % .value - (string), value to use 73 | % 74 | % OPTIONAL INPUTS (varargin, property/value pairs) 75 | % ======================================================================= 76 | % CAST_OUTPUT : (default true) output is uint8, useful if the body 77 | % of the response is not text 78 | % ENCODING : (default ''), ENCODING input to function unicode2native 79 | % FOLLOW_REDIRECTS : (default true), if false 3xx status codes will 80 | % be returned and need to be handled by the user, 81 | % note this does not handle javascript or meta tag 82 | % redirects, just server based ones 83 | % READ_TIMEOUT : (default 0), 0 means no timeout, value is in 84 | % milliseconds 85 | % 86 | % EXAMPLES 87 | % ======================================================================= 88 | % GET: 89 | % -------------------------------------------- 90 | % url = 'http://www.mathworks.com/matlabcentral/fileexchange/'; 91 | % query = 'urlread2'; 92 | % params = {'term' query}; 93 | % queryString = http_paramsToString(params,1); 94 | % url = [url '?' queryString]; 95 | % [output,extras] = urlread2(url); 96 | % 97 | % POST: 98 | % -------------------------------------------- 99 | % url = 'http://posttestserver.com/post.php'; 100 | % params = {'testChars' char([2500 30000]) 'new code' '?'}; 101 | % [paramString,header] = http_paramsToString(params,1); 102 | % [output,extras] = urlread2(url,'POST',paramString,header); 103 | % 104 | % From behind a firewall, use the Preferences to set your proxy server. 105 | % 106 | % See Also: 107 | % http_paramsToString 108 | % unicode2native 109 | % native2unicode 110 | % 111 | % Subfunctions: 112 | % fixHeaderCasing - small subfunction to fix case errors encountered in real 113 | % world, requires updating when casing doesn't match expected form, like 114 | % if someone sent the header content-Encoding instead of 115 | % Content-Encoding 116 | % 117 | % Based on original urlread code by Matthew J. Simoneau 118 | % 119 | % VERSION = 1.1 120 | 121 | in.CAST_OUTPUT = true; 122 | in.FOLLOW_REDIRECTS = true; 123 | in.READ_TIMEOUT = 0; 124 | in.ENCODING = ''; 125 | 126 | %Input handling 127 | %--------------------------------------- 128 | if ~isempty(varargin) 129 | for i = 1:2:numel(varargin) 130 | prop = upper(varargin{i}); 131 | value = varargin{i+1}; 132 | if isfield(in,prop) 133 | in.(prop) = value; 134 | else 135 | error('Unrecognized input to function: %s',prop) 136 | end 137 | end 138 | end 139 | 140 | if ~exist('method','var') || isempty(method), method = 'GET'; end 141 | if ~exist('body','var'), body = ''; end 142 | if ~exist('headersIn','var'), headersIn = []; end 143 | 144 | assert(usejava('jvm'),'Function requires Java') 145 | 146 | import com.mathworks.mlwidgets.io.InterruptibleStreamCopier; 147 | com.mathworks.mlwidgets.html.HTMLPrefs.setProxySettings %Proxy settings need to be set 148 | 149 | %Create a urlConnection. 150 | %----------------------------------- 151 | urlConnection = getURLConnection(urlChar); 152 | %For HTTP uses sun.net.www.protocol.http.HttpURLConnection 153 | %Might use ice.net.HttpURLConnection but this has more overhead 154 | 155 | %SETTING PROPERTIES 156 | %------------------------------------------------------- 157 | urlConnection.setRequestMethod(upper(method)); 158 | urlConnection.setFollowRedirects(in.FOLLOW_REDIRECTS); 159 | urlConnection.setReadTimeout(in.READ_TIMEOUT); 160 | 161 | for iHeader = 1:length(headersIn) 162 | curHeader = headersIn(iHeader); 163 | urlConnection.setRequestProperty(curHeader.name,curHeader.value); 164 | end 165 | 166 | if ~isempty(body) 167 | %Ensure vector? 168 | if size(body,1) > 1 169 | if size(body,2) > 1 170 | error('Input parameter to function: body, must be a vector') 171 | else 172 | body = body'; 173 | end 174 | end 175 | 176 | if ischar(body) 177 | %NOTE: '' defaults to Matlab's default encoding scheme 178 | body = unicode2native(body,in.ENCODING); 179 | elseif ~(strcmp(class(body),'uint8') || strcmp(class(body),'int8')) 180 | error('Function input: body, should be of class char, uint8, or int8, detected: %s',class(body)) 181 | end 182 | 183 | urlConnection.setRequestProperty('Content-Length',int2str(length(body))); 184 | urlConnection.setDoOutput(true); 185 | outputStream = urlConnection.getOutputStream; 186 | outputStream.write(body); 187 | outputStream.close; 188 | else 189 | urlConnection.setRequestProperty('Content-Length','0'); 190 | end 191 | 192 | %========================================================================== 193 | % Read the data from the connection. 194 | %========================================================================== 195 | %This should be done first because it tells us if things are ok or not 196 | %NOTE: If there is an error, functions below using urlConnection, notably 197 | %getResponseCode, will fail as well 198 | try 199 | inputStream = urlConnection.getInputStream; 200 | isGood = true; 201 | catch ME 202 | isGood = false; 203 | %NOTE: HTTP error codes will throw an error here, we'll allow those for now 204 | %We might also get another error in which case the inputStream will be 205 | %undefined, those we will throw here 206 | inputStream = urlConnection.getErrorStream; 207 | 208 | if isempty(inputStream) 209 | msg = ME.message; 210 | I = strfind(msg,char([13 10 9])); %see example by setting timeout to 1 211 | %Should remove the barf of the stack, at ... at ... at ... etc 212 | %Likely that this could be improved ... (generate link with full msg) 213 | if ~isempty(I) 214 | msg = msg(1:I(1)-1); 215 | end 216 | fprintf(2,'Response stream is undefined\n below is a Java Error dump (truncated):\n'); 217 | error(msg) 218 | end 219 | end 220 | 221 | %POPULATING HEADERS 222 | %-------------------------------------------------------------------------- 223 | allHeaders = struct; 224 | allHeaders.Response = {char(urlConnection.getHeaderField(0))}; 225 | done = false; 226 | headerIndex = 0; 227 | 228 | while ~done 229 | headerIndex = headerIndex + 1; 230 | headerValue = char(urlConnection.getHeaderField(headerIndex)); 231 | if ~isempty(headerValue) 232 | headerName = char(urlConnection.getHeaderFieldKey(headerIndex)); 233 | headerName = fixHeaderCasing(headerName); %NOT YET FINISHED 234 | 235 | %Important, for name safety all hyphens are replace with underscores 236 | headerName(headerName == '-') = '_'; 237 | if isfield(allHeaders,headerName) 238 | allHeaders.(headerName) = [allHeaders.(headerName) headerValue]; 239 | else 240 | allHeaders.(headerName) = {headerValue}; 241 | end 242 | else 243 | done = true; 244 | end 245 | end 246 | 247 | firstHeaders = struct; 248 | fn = fieldnames(allHeaders); 249 | for iHeader = 1:length(fn) 250 | curField = fn{iHeader}; 251 | firstHeaders.(curField) = allHeaders.(curField){1}; 252 | end 253 | 254 | status = struct(... 255 | 'value', urlConnection.getResponseCode(),... 256 | 'msg', char(urlConnection.getResponseMessage)); 257 | 258 | %PROCESSING OF OUTPUT 259 | %---------------------------------------------------------- 260 | byteArrayOutputStream = java.io.ByteArrayOutputStream; 261 | % This StreamCopier is unsupported and may change at any time. OH GREAT :/ 262 | isc = InterruptibleStreamCopier.getInterruptibleStreamCopier; 263 | isc.copyStream(inputStream,byteArrayOutputStream); 264 | inputStream.close; 265 | byteArrayOutputStream.close; 266 | 267 | if in.CAST_OUTPUT 268 | charset = ''; 269 | 270 | %Extraction of character set from Content-Type header if possible 271 | if isfield(firstHeaders,'Content_Type') 272 | text = firstHeaders.Content_Type; 273 | %Always open to regexp improvements 274 | charset = regexp(text,'(?<=charset=)[^\s]*','match','once'); 275 | end 276 | 277 | if ~isempty(charset) 278 | output = native2unicode(typecast(byteArrayOutputStream.toByteArray','uint8'),charset); 279 | else 280 | output = char(typecast(byteArrayOutputStream.toByteArray','uint8')); 281 | end 282 | else 283 | %uint8 is more useful for later charecter conversions 284 | %uint8 or int8 is somewhat arbitary at this point 285 | output = typecast(byteArrayOutputStream.toByteArray','uint8'); 286 | end 287 | 288 | extras = struct; 289 | extras.allHeaders = allHeaders; 290 | extras.firstHeaders = firstHeaders; 291 | extras.status = status; 292 | %Gets eventual url even with redirection 293 | extras.url = char(urlConnection.getURL); 294 | extras.isGood = isGood; 295 | 296 | 297 | 298 | end 299 | 300 | function headerNameOut = fixHeaderCasing(headerName) 301 | %fixHeaderCasing Forces standard casing of headers 302 | % 303 | % headerNameOut = fixHeaderCasing(headerName) 304 | % 305 | % This is important for field access in a structure which 306 | % is case sensitive 307 | % 308 | % Not yet finished. 309 | % I've been adding to this function as problems come along 310 | 311 | switch lower(headerName) 312 | case 'location' 313 | headerNameOut = 'Location'; 314 | case 'content_type' 315 | headerNameOut = 'Content_Type'; 316 | otherwise 317 | headerNameOut = headerName; 318 | end 319 | end 320 | 321 | %========================================================================== 322 | %========================================================================== 323 | %========================================================================== 324 | 325 | function urlConnection = getURLConnection(urlChar) 326 | %getURLConnection 327 | % 328 | % urlConnection = getURLConnection(urlChar) 329 | 330 | % Determine the protocol (before the ":"). 331 | protocol = urlChar(1:find(urlChar==':',1)-1); 332 | 333 | 334 | % Try to use the native handler, not the ice.* classes. 335 | try 336 | switch protocol 337 | case 'http' 338 | %http://www.docjar.com/docs/api/sun/net/www/protocol/http/HttpURLConnection.html 339 | handler = sun.net.www.protocol.http.Handler; 340 | case 'https' 341 | handler = sun.net.www.protocol.https.Handler; 342 | end 343 | catch ME 344 | handler = []; 345 | end 346 | 347 | % Create the URL object. 348 | try 349 | if isempty(handler) 350 | url = java.net.URL(urlChar); 351 | else 352 | url = java.net.URL([],urlChar,handler); 353 | end 354 | catch ME 355 | error('Failure to parse URL or protocol not supported for:\nURL: %s',urlChar); 356 | end 357 | 358 | % Get the proxy information using MathWorks facilities for unified proxy 359 | % preference settings. 360 | mwtcp = com.mathworks.net.transport.MWTransportClientPropertiesFactory.create(); 361 | proxy = mwtcp.getProxy(); 362 | 363 | % Open a connection to the URL. 364 | if isempty(proxy) 365 | urlConnection = url.openConnection; 366 | else 367 | urlConnection = url.openConnection(proxy); 368 | end 369 | 370 | 371 | end 372 | -------------------------------------------------------------------------------- /urlread_General.m: -------------------------------------------------------------------------------- 1 | function [s,status] = urlread_General(url,varargin) 2 | %URLREAD Returns the contents of a URL as a string. 3 | % S = URLREAD('URL') reads the content at a URL into a string, S. If the 4 | % server returns binary data, the string will contain garbage. 5 | % 6 | % S = URLREAD('URL','method',PARAMS) passes information to the server as 7 | % part of the request. The 'method' can be 'get', or 'post' and PARAMS is a 8 | % cell array of param/value pairs. 9 | % 10 | % S = URLREAD(...,'Timeout',T) sets a timeout, in seconds, when the function 11 | % will error rather than continue to wait for the server to respond or send 12 | % data. 13 | % 14 | % [S,STATUS] = URLREAD(...) catches any errors and returns 1 if the file 15 | % downloaded successfully and 0 otherwise. 16 | % 17 | % Examples: 18 | % s = urlread('http://www.mathworks.com') 19 | % s = urlread('ftp://ftp.mathworks.com/README') 20 | % s = urlread(['file:///' fullfile(prefdir,'history.m')]) 21 | % 22 | % From behind a firewall, use the Preferences to set your proxy server. 23 | % 24 | % See also URLWRITE. 25 | 26 | % Matthew J. Simoneau, 13-Nov-2001 27 | % Copyright 1984-2011 The MathWorks, Inc. 28 | 29 | % Do we want to throw errors or catch them? 30 | if nargout == 2 31 | catchErrors = true; 32 | else 33 | catchErrors = false; 34 | end 35 | 36 | [s,status] = urlreadwrite_General(mfilename,catchErrors,url,varargin{:}); 37 | -------------------------------------------------------------------------------- /urlreadwrite_General.m: -------------------------------------------------------------------------------- 1 | function [output,status] = urlreadwrite_General(fcn,catchErrors,varargin) 2 | %URLREADWRITE A helper function for URLREAD and URLWRITE. 3 | 4 | % Matthew J. Simoneau, June 2005 5 | % Sharath Prabhal, September 2012 6 | % Copyright 1984-2012 The MathWorks, Inc. 7 | 8 | % This function requires Java. 9 | error(javachk('jvm',fcn)) 10 | import com.mathworks.mlwidgets.io.InterruptibleStreamCopier; 11 | 12 | % Be sure the proxy settings are set. 13 | com.mathworks.mlwidgets.html.HTMLPrefs.setProxySettings 14 | 15 | % Parse inputs. 16 | inputs = parseInputs(fcn,varargin); 17 | urlChar = inputs.url; 18 | 19 | % Set default outputs. 20 | output = ''; 21 | status = 0; 22 | 23 | % GET method. Tack param/value to end of URL. 24 | for i = 1:2:numel(inputs.get) 25 | if (i == 1), separator = '?'; else separator = '&'; end 26 | param = char(java.net.URLEncoder.encode(inputs.get{i})); 27 | value = char(java.net.URLEncoder.encode(inputs.get{i+1})); 28 | urlChar = [urlChar separator param '=' value]; 29 | end 30 | 31 | % Create a urlConnection. 32 | [urlConnection,errorid] = getUrlConnection(urlChar,inputs.timeout,... 33 | inputs.useragent,inputs.authentication, inputs.username, inputs.password); 34 | if isempty(urlConnection) 35 | if catchErrors, return 36 | else error(mm(fcn,errorid)); 37 | end 38 | end 39 | 40 | % POST method. Write param/values to server. 41 | if ~isempty(inputs.post) 42 | try 43 | urlConnection.setDoOutput(true); 44 | urlConnection.setRequestProperty( ... 45 | 'Content-Type','application/x-www-form-urlencoded'); 46 | printStream = java.io.PrintStream(urlConnection.getOutputStream); 47 | for i=1:2:length(inputs.post) 48 | if (i > 1), printStream.print('&'); end 49 | param = char(java.net.URLEncoder.encode(inputs.post{i})); 50 | value = char(java.net.URLEncoder.encode(inputs.post{i+1})); 51 | printStream.print([param '=' value]); 52 | end 53 | printStream.close; 54 | catch 55 | if catchErrors, return 56 | else error(mm(fcn,'PostFailed')); 57 | end 58 | end 59 | end 60 | 61 | % Get the outputStream. 62 | switch fcn 63 | case 'urlread_General' 64 | outputStream = java.io.ByteArrayOutputStream; 65 | case 'urlwrite_General' 66 | [file,outputStream] = getFileOutputStream(inputs.filename); 67 | end 68 | 69 | % Read the data from the connection. 70 | try 71 | inputStream = urlConnection.getInputStream; 72 | % This StreamCopier is unsupported and may change at any time. 73 | isc = InterruptibleStreamCopier.getInterruptibleStreamCopier; 74 | isc.copyStream(inputStream,outputStream); 75 | inputStream.close; 76 | outputStream.close; 77 | catch e 78 | outputStream.close; 79 | if strcmp(fcn,'urlwrite_General') 80 | delete(file); 81 | end 82 | if catchErrors 83 | return 84 | elseif strfind(e.message,'java.net.SocketTimeoutException:') 85 | error(mm(fcn,'Timeout')); 86 | elseif strfind(e.message,'java.net.UnknownHostException:') 87 | host = regexp(e.message,'java.net.UnknownHostException: ([^\n\r]*)','tokens','once'); 88 | error(mm(fcn,'UnknownHost',host{1})); 89 | elseif strfind(e.message,'java.io.FileNotFoundException:') 90 | error(mm(fcn,'FileNotFound')); 91 | elseif strfind(e.message,'java.net.Authenticator.requestPasswordAuthentication') 92 | error(mm(fcn,'BasicAuthenticationFailed')); 93 | else 94 | error(mm(fcn,'ConnectionFailed')); 95 | end 96 | end 97 | 98 | if isempty(inputs.charset) 99 | contentType = char(urlConnection.getContentType); 100 | charsetMatch = regexp(contentType,'charset=([A-Za-z0-9\-\.:_])*','tokens','once'); 101 | if isempty(charsetMatch) 102 | if strncmp(urlChar,'file:',4) 103 | charset = char(java.lang.System.getProperty('file.encoding')); 104 | else 105 | charset = 'UTF-8'; 106 | end 107 | else 108 | charset = charsetMatch{1}; 109 | end 110 | else 111 | charset = inputs.charset; 112 | end 113 | 114 | switch fcn 115 | case 'urlread_General' 116 | output = native2unicode(typecast(outputStream.toByteArray','uint8'),charset); 117 | case 'urlwrite_General' 118 | output = char(file.getAbsolutePath); 119 | end 120 | status = 1; 121 | 122 | function m = mm(fcn,id,varargin) 123 | m = message(['MATLAB:' fcn ':' id],varargin{:}); 124 | 125 | function results = parseInputs(fcn,args) 126 | p = inputParser; 127 | p.addRequired('url',@(x)validateattributes(x,{'char'},{'nonempty'})) 128 | if strcmp(fcn,'urlwrite_General') 129 | p.addRequired('filename',@(x)validateattributes(x,{'char'},{'nonempty'})) 130 | end 131 | p.addParamValue('get',{},@(x)checkpv(fcn,x)) 132 | p.addParamValue('post',{},@(x)checkpv(fcn,x)) 133 | p.addParamValue('timeout',[],@isnumeric) 134 | p.addParamValue('useragent',[],@ischar) 135 | p.addParamValue('charset',[],@ischar) 136 | p.addParamValue('authentication', [], @ischar) 137 | p.addParamValue('username', [], @ischar) 138 | p.addParamValue('password', [], @ischar) 139 | p.FunctionName = fcn; 140 | p.parse(args{:}) 141 | results = p.Results; 142 | 143 | function checkpv(fcn,params) 144 | if mod(length(params),2) == 1 145 | error(mm(fcn,'InvalidInput')); 146 | end 147 | 148 | function [urlConnection,errorid] = getUrlConnection(urlChar,timeout,... 149 | userAgent,authentication,userName,password) 150 | 151 | import org.apache.commons.codec.binary.Base64; 152 | % Default output arguments. 153 | urlConnection = []; 154 | errorid = ''; 155 | 156 | % Determine the protocol (before the ":"). 157 | protocol = urlChar(1:find(urlChar==':',1)-1); 158 | 159 | % Try to use the native handler, not the ice.* classes. 160 | switch protocol 161 | case 'http' 162 | try 163 | handler = sun.net.www.protocol.http.Handler; 164 | catch exception %#ok 165 | handler = []; 166 | end 167 | case 'https' 168 | try 169 | handler = sun.net.www.protocol.https.Handler; 170 | catch exception %#ok 171 | handler = []; 172 | end 173 | otherwise 174 | handler = []; 175 | end 176 | 177 | % Create the URL object. 178 | try 179 | if isempty(handler) 180 | url = java.net.URL(urlChar); 181 | else 182 | url = java.net.URL([],urlChar,handler); 183 | end 184 | catch exception %#ok 185 | errorid = 'InvalidUrl'; 186 | return 187 | end 188 | 189 | % Get the proxy information using the MATLAB proxy API. 190 | proxy = com.mathworks.webproxy.WebproxyFactory.findProxyForURL(url); 191 | 192 | % Open a connection to the URL. 193 | if isempty(proxy) 194 | urlConnection = url.openConnection; 195 | else 196 | urlConnection = url.openConnection(proxy); 197 | end 198 | 199 | % Set MATLAB as the User Agent 200 | if isempty(userAgent) 201 | userAgent = ['MATLAB R' version('-release') ' ' version('-description')]; 202 | end 203 | urlConnection.setRequestProperty('User-Agent', userAgent); 204 | 205 | % If username and password exists, perform basic authentication 206 | if strcmpi(authentication,'Basic') 207 | usernamePassword = [userName ':' password]; 208 | usernamePasswordBytes = int8(usernamePassword)'; 209 | usernamePasswordBase64 = char(Base64.encodeBase64(usernamePasswordBytes)'); 210 | urlConnection.setRequestProperty('Authorization', ['Basic ' usernamePasswordBase64]); 211 | end 212 | 213 | % Set the timeout. 214 | if (nargin > 2 && ~isempty(timeout)) 215 | % Handle any numeric datatype and convert. 216 | milliseconds = int32(double(timeout)*1000); 217 | % Java inteprets 0 as no timeout. This would be confusing if we rounded 218 | % to 0 from something else, e.g. "'timeout',.0001". 219 | if milliseconds == 0 220 | milliseconds = int32(1); 221 | end 222 | urlConnection.setConnectTimeout(milliseconds); 223 | urlConnection.setReadTimeout(milliseconds); 224 | end 225 | 226 | function [file,fileOutputStream] = getFileOutputStream(location) 227 | % Specify the full path to the file so that getAbsolutePath will work when the 228 | % current directory is not the startup directory and urlwrite is given a 229 | % relative path. 230 | file = java.io.File(location); 231 | if ~file.isAbsolute 232 | location = fullfile(pwd,location); 233 | file = java.io.File(location); 234 | end 235 | 236 | try 237 | % Make sure the path isn't nonsense. 238 | file = file.getCanonicalFile; 239 | % Open the output file. 240 | fileOutputStream = java.io.FileOutputStream(file); 241 | catch 242 | error(mm('urlwrite_General','InvalidOutputLocation',char(file.getAbsolutePath))); 243 | end 244 | -------------------------------------------------------------------------------- /urlwrite_General.m: -------------------------------------------------------------------------------- 1 | function [f,status] = urlwrite_General(url,filename,varargin) 2 | %URLWRITE Save the contents of a URL to a file. 3 | % URLWRITE(URL,FILENAME) saves the contents of a URL to a file. FILENAME 4 | % can specify the complete path to a file. If it is just the name, it will 5 | % be created in the current directory. 6 | % 7 | % F = URLWRITE(...) returns the path to the file. 8 | % 9 | % F = URLWRITE(...,METHOD,PARAMS) passes information to the server as 10 | % part of the request. The 'method' can be 'get', or 'post' and PARAMS is a 11 | % cell array of param/value pairs. 12 | % 13 | % URLWRITE(...,'Timeout',T) sets a timeout, in seconds, when the function 14 | % will error rather than continue to wait for the server to respond or send 15 | % data. 16 | % 17 | % [F,STATUS] = URLWRITE(...) catches any errors and returns the error code. 18 | % 19 | % Examples: 20 | % urlwrite('http://www.mathworks.com/',[tempname '.html']) 21 | % urlwrite('ftp://ftp.mathworks.com/README','readme.txt') 22 | % urlwrite(['file:///' fullfile(prefdir,'history.m')],'myhistory.m') 23 | % 24 | % From behind a firewall, use the Preferences to set your proxy server. 25 | % 26 | % See also URLREAD. 27 | 28 | % Matthew J. Simoneau, 13-Nov-2001 29 | % Copyright 1984-2011 The MathWorks, Inc. 30 | 31 | % Do we want to throw errors or catch them? 32 | if nargout == 2 33 | catchErrors = true; 34 | else 35 | catchErrors = false; 36 | end 37 | 38 | [f,status] = urlreadwrite_General(mfilename,catchErrors,url,filename,varargin{:}); 39 | -------------------------------------------------------------------------------- /《量化投资:以MATLAB为工具》书籍源码&数据下载二维码.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/faruto/FQuantToolBox/6e9e3fadc608c509123feb2af26509e73962b648/《量化投资:以MATLAB为工具》书籍源码&数据下载二维码.png --------------------------------------------------------------------------------