PHP Application to Estimate SZ162411 Net Value
Aug 18, 2015
As my CSR Stock is turning into cash soon, I am considering to use the USD to trade XOP while using my other CNY to trade SZ162411 together.
I was watching stock quotations on Yahoo and Sina everyday, and always need to click on the calculator application to convert the price between XOP and SZ162411, soon I got bored.
Later I thought of my first PHP application 5 years ago, and decided to write my second PHP application.
It was planned to put all the usual stock quotations together, and to estimate SZ162411 net value based on XOP, ^SPSIOP and USDCNY exchange rate.
Today the first version is released, and I am writing this record of programming details for future reference.
Thanks abkoooo for Sina realtime US stock data format.
Using Sina realtime source for US and Chinese stocks, oil futures and forex: http://hq.sinajs.cn/list=gb_xop,sz162411,hf_CL,USDCNY
At first I found that fopen will always fail to open those urls, maybe my Yahoo Web Hosting does not support allow_url_fopen.
I searched and found curl to solve this problem, copied some curl code to my url_get_contents function with name similar as file_get_contents.
To optimize web response time, I used 2 files gb_xop.txt and sz162411.txt to save last updated stock data.
The following are checked:
- New request in the same minute using data in original files directly.
- Using gb_xop.txt for US stock data after US market closed.
- Using sz162411.txt for Chinese stock data after Chinese market closed.
Similarly, oil future data is stored in file hf_cl.txt, and USDCNY forex data in usdcny.txt.
Aug 20, 2015
To set up my own trading rules, and to avoid following the market all night, I plan to trade XOP simply on Simple Moving Average (SMA) values.
This version added the premium of current trading price comparing with XOP estimation of SZ162411 net value,
and the days in past 100 trading days did the estimated SMA value fitted in the trading range.
The historic data of XOP only need to update once a day, using Yahoo stock historic data: https://finance.yahoo.com/quote/XOP/history
The official fund net value only need to update once a day too.
Using file f_162411.txt for official SZ162411 net value from http://hq.sinajs.cn/list=f_162411,
as I do not konw when the data will be updated, I update it once an hour stupidly.
Using debug file debug.txt for temp data checking.
Aug 21, 2015
After released the link of this tool, I checked the data of Google Analytics yesterday. During the 3 days there are 584 visits from 289 different IP address.
Unlike the usual Palmmicro visitors, 1/3 of the tool visitors used mobile phone. So I added the UI optimization for mobile phone in a hurry.
Using http://mobiledetect.net/ to detect if it is a mobile phone visit.
Following the developer's advice, I copied the code github and put it separately in /php/class/Mobile_Detect.php.
Aug 27, 2015
The best way to organize the source code is to write more similar LOF net value estimation software.
I bought 2 HK ETF related LOF with recent stock market crash and added them.
Although I only watched US market crash, I still added BOSERA S&P 500 net value tool for possible future usage.
Sep 13, 2015
After login, user can now input related stock transaction record. And we make SZ162411 and XOP arbitrage analysis based on those record.
The input and handling of stock transaction record is in file /woody/res/php/_edittransactionform.php and /woody/res/php/_submittransaction.php.
Visual C++ coded Woody's Web Tool is modified to generate _submitXXX.php file automatically when insert copy of a _editXXXform.php file.
Jan 26, 2016
Add date display in related price time items following the advice from oldwain.
The original version omitted date display because I thougth it was obvious. And it is obvious too that not every one is as familar with both USA and China time as I am.
Although it is a small separating data and display change, I can not help myself to mofidy a lot of code.
The original StockReference class is now a base class for FutureReference and ForexReference.
In this way, the display is unified.
Period Three Implies Chaos
Feb 26, 2016
SZ162411 is trading more than 10% higher than its net value recently, the max premium as high as 17%, so the XOP and SZ162411 arbitrage is not possible now.
Continuing to organzie the similar code, added MysqlReference and MyStockReference class.
FutureReference and ForexReference are now extended from MysqlReference, same as the new MyStockReference.
We called MySQL related function in MysqlReference class, put history and calibration database operation in the same place.
US Daylight Saving Time
March 14, 2016
A bug is found as US enter daylight saving time: date_default_timezone_set('EST') is not considering daylight saving,
need to use date_default_timezone_set('America/New_York') or date_default_timezone_set('EDT').
March 25, 2016
As Gold future GC is not trading on Easter holiday, I get the chance to adjust the net value estimation for Chinese Gold ETF.
Different users have been suggesting to add estimation value in the fund history table of SZ162411.
Except for not willing to show my possible error directly, I did not add it because the change is realtime, and I don't know when to record it, after US market close or Chinese market close?
In the LOF code, the variable for estimation value was originally in _LofGroup class.
With my new _GoldEtfGroup class again having the same class member of FundReference class,
naturally I moved the estimation value to FundReference class. And when estimaation value and net value variable are put together, the data structure leads my mind again,
suddenly I realized that it is most reasonable to record the estimation value in the same time when the current day net value is recorded!
The average page view of my net value pages in a normal trading day is around 1000 now, the max day is nearly 1700. I have been optimizing my software for more page views in the future.
As the SMA caculation only need to be done once in a day, it is natural to save the result instead of calculate it with every page view.
I have been thinking about it but never did anything, until I finished the adjustment of 7 gold ETF, I realized that the SMA of GLD need to be calculated in 8 pages including the GC gold future page.
I feel I can not stand it any more.
Based on the experience of finding Mobile-Detect code on internet, I underestimated the efforts to find a ready php class for config file read and write.
An easy found one cost 5 USD, it says to support file and mysql for configuration at the same time, as I do not like too many tables in mysql and only interested in file config,
I think 5 USD may be a waste of money.
As last I found the free INIFile.
The class only support config read and write on an existing file, still as a PHP new programmer, I spent a few hours to modify it and finally made it works with my pages.
Sina Realtime HK Stock Data
Apr 23, 2016
With the help of rdcheju,
now using Sina realtime HK stock data(http://hq.sinajs.cn/list=rt_hk02828) to replace original Sina Stock Data which has 15 minutes delay.
On last Thursday the total page view of my net value pages was over 2200, this encouraged me to do more page speed optimization.
The Most Stupid Bug in Recent Years
May 15, 2016
Last week USDCNY was rising significantly again, and a new bug of SZ162411 net value estimation floated on water. On Friday, May 13, my estimation was about 1% higher than the official data.
I began to check the problem yesterday, found that the last automatic calibration was done on the evening of May 12, after the official net value of May 11 data released.
And the automatic calibration on May 13 was not done yet. In other words, the calibration was one day late for quite some time now, but when USDCNY had little change, the problem was ignored.
It was easy to find the bug, I used the simplest way to fix the estimation bug caused by continue Chinese and USA market close after Chinese New Year.
Because only Hongkong LOF would have the chance of official LOF net value newer than ETF, I rewrote part of the code by checking if it was HK LOF,
and modified an actually unrelated code, what should be $iHours = STOCK_HOUR_END + ($this->usdhkd_ref ? 0 : 24); was written as $iHours = STOCK_HOUR_END + ($this->usdhkd_ref) ? 0 : 24;
But this bug made me feel very bad, this time I can not say I am still a 6 years new PHP programmer. As a proud 25 years C programmer, this is also a very stupid bug in C language!
T+1 Estimation with Current CL Factor in
Aug 18, 2016
Many people's Excel sheet has this one, so I added it too. Here is the difference between offical estimation, fair estimation and realtime estimation of SZ162411 net value.
|T day trading
|T+1 day CL future
|USDCNY Reference Rate
How to Precisely Estimate the Net Value of SZ162411
Sep 27, 2016
Added 95% position for all LOF net value estimation.
Automatic and manual calibration history
Oct 6, 2016
SZ162411 calibration history.
Crazy T+1 Moving Average
March 27, 2018
XOP 2020-02-14数据牛熊分数: 1 历史价格记录