Skip to content

Latest commit

 

History

History
565 lines (444 loc) · 38.3 KB

CHANGELOG.md

File metadata and controls

565 lines (444 loc) · 38.3 KB

CHANGELOG

This file serves as the journal for the half_tael_DQN project.


Broadcast

2019-07-10 | A short style guide for updating this CHANGELOG.md.

  • The CHANGELOG.md has three sections.
    • Broadcast: Briefing of upcoming events or reminders (like this one).
    • Meeting: Summaries for meetings.
    • Development Journal: Records for development updates.
  • For the sake of consistency, I suggest we update this CHANGELOG.md in a date descending order (new-to-old) with a headline format of YYYY-MM-DD | Highlight | Name. Note the Highlight and Name parts can be omitted if not applicable, e.g.
    • This broadcast headline, which omits Name.
    • Under Development Journal as 2019-04-10 | Henry Zhong, which omits Highlight.

Meeting

2019-09-02 | Scrum #11 | Henry (final delivery for Graphen.ai).\

2019-08-25 | Scrum #10 | Henry (end-of-internship review).

2019-08-16 | Scrum #9 | Henry (report to Ching-Yung Lin and Oscar Tseng).

2019-08-14 | Scrum #8 | Henry.

  • Henry
    1. ✅ 🚧 Refactor half_tael_v2.0 to v3.0, in compliant with DQN_v2.5 (multiple currency model working with the trading platform).
    2. Anita v2.0
      • Postponed as legacy Anita is unusable, check 2019-08-08 | Legacy Anita plot hole discovered | Henry in section Development Journal for details.

2019-08-12 | Scrum #7 | Henry, Steven.

  • Henry

    1. ✅ Test the reward design (for Anita).
    2. Anita v2.0
      • Postponed due to prioritized on debugging DQN v2.5.
    3. ✅ DQN v2.5: Debugged and partially adjusted the CNN + DQN model which supports multiple (>2) currencies based on Steven X.'s design (ef6e716). Presented a runnable demo only on a specific dummy data set -- Henry.
  • Steven

    1. ✅ DQN v2.5: Research and redesigned DQN_v1.0 as DQN_v2.5 to support multiple (>2) currencies using a CNN + DQN structure.
      • Works presented as ef6e716. Need debug.
      • Absent, but marked as "green check" since goal (DQN v2.5) accomplished -- Henry.

2019-08-07 | Scrum #6 | Henry, Steven.

  • Henry
    1. ✅ Understand CNN basic.
  • Steven
    1. ✅ Fully understand the basic of CNN as in the relationship between w_1, b_1, n_features, and input data_env
    • ❌ 🚧 DQN v2.5.
      • Postpone to 2019-08-09, but made significant progress on understanding the mapping of matrix convolution.

2019-08-06 | Scrum #5 | Henry, Steven.

2019-08-02 | Scrum #4 | Henry, Steven.

2019-07-30 | Scrum #3 | Henry, Steven, Jian.

  • Goals
    • Henry

      1. Draft version control standard and contribution guideline (2019-07-26).
      • Finish basic DQN learning.
    • Steven 2. Document the two-currency DQN model (2019-07-26).

    • Jian 3. Develop a set of evaluation functions to evaluate the status (weight) of certain metrics introduced in Anita Folder. * Such functions should take _time, _currency_pair, _volume, trade_action (long, short, hold) and any other necessary parameters (e.g. historical trade_log) as inputs and return a float number between -1 to 1 as a reflection of the status of such metrics at this particular position.

        * Sample data as:
            * [USD_JPY_GBP_2017-01-01T00:00:00_2018-01-01T00:00:00_M5.csv](https://github.com/choH/half_tael_DQN/blob/master/arena_data/USD_JPY_GBP_2017-01-01T00:00:00_2018-01-01T00:00:00_M5.csv) (74,277 rows).
            * If the above data is too huge , you may always refer to [USD_JPY_GBP_2019-01-01T00:00:00_2019-02-01T00:00:00_M5.csv](https://github.com/choH/half_tael_DQN/blob/master/arena_data/USD_JPY_GBP_2019-01-01T00:00:00_2019-02-01T00:00:00_M5.csv) as a lightweight alternative (6,358 rows).
      
  • Review

2019-07-24 | Scrum #2 | Henry, Jian, Steven.

  • Goals:

    • Henry
      1. Implement trading interface.
      • Write user manual on such trading interface.
      • Draft version control standard and contribution guideline.
    • Steven
      1. Run a trial DQN model on any USD_JPY file in ./dummy_data.
    • Jian
      1. Help Steven on building the basic DQN model.
      • Quantified Anita's personality on trading behavior.
      • Research some high-end DQN structure and make a presentation.
  • Review

    • Henry

      1. trade_interface.py fully developed by commit #5d86b5d.
      • ✅ Available as:
      • Version control standard and contribution guideline postpone to 2019-07-25.
    • Steven

      1. ✅ Trial DQN is runnable, will commit after Henry's version control standard and contribution guideline becomes available.
    • Jian

      1. ☑️ Trial DQN is a solo work done by Steven, however Jian did implemented a Cartpole demo.
      • ❌ Did not delivery as Jian believes it is not feasible to do it stand-alone (without the DQN code).
        • After discussion, we all agree it is doable and such task is postpone to 2019-07-30.
      • ✅ Introduced some fundamental DQN features (remember, replay).

2019-07-19 | Scrum #1 | Henry, Steven.

  • Goals

    • ALL:
      1. Get familiar with basic Q-learning and DQN concept in general.
    • Henry:
      1. Build a basic wrapper to communicate with OANDA API as the backend of the project. Anul's code Oanda_Trader.py can be use as reference.
    • Steven:
      1. Run a trial DQN model on SP 500 USD_JPY_0.csv.
        • Task change due to CSV file of foreign exchange between USD and JPY is easily obtainable -- Henry.
    • Jian:
      1. Research and present some insight regarding the possible designs of DQN model.
      • Understand the concept of Anita, and define a quantified standard for "trading personality" according to Mapping Personality Traits to Investment Behavior (Revised) and Strategies and Metrics.xlsx
        • Task change due to update form Dr. Lin regarding Anita. As "trading bot with personalities" is the unique selling point of this project, we should only research in designs which are compatible with such idea. Thus we should quantify the concept of "trading personality" first -- Henry.
  • Review

    • All

      • Henry: ❌ 🚧 Work-in-progress on DQN.
      • Steven: ✅ Basic DQN learned.
      • Jian: ✅ Basic DQN learned
    • Henry

      1. ✅ Delivered by commit ac4d217.
    • Steven 2. ❌ 🚧 Work-in-progress, will delivery by on 2019-07-24.

    • Jian

      1. ❓ Absent for the day, will catch up on 2019-07-22 -- Henry.
        • ❌ 🚧 Work-in-progress, will deliver by on 2019-07-24.

2019-07-11 | Kick-off briefing | Anul Sinha, Henry, Jian, Steven.

  • Anul gave a presentation of his forex side-project, mainly regarding the method of interaction with OANDA, his model try-out, and why he abandoned this project.
  • Due to the lacks of documentation of Anul's work, we decided to not to take over his project (also because he has moved on to a more combined design base on his forex), but to build our own bot. However, we will take his code as an important reference, especially regarding the OANDA API part and model environment setup.

Development Journal

2019-09-02 | half_tael_DQN v4.5 release | Henry.

  • Update CHANGELOG.md and 🔰 User Manual for anita_interface.py.
  • Remove (and regenerate to discard the published one) OANDA credential.
  • Fix command line instruction mistake in README.md Run section.
  • Update README.md with information regarding anita_v2.0.
  • Bugfix log output directory — and also raw_data folder? — not exist issue (with mkdir).
  • Provide a Trade_Interface config input with longer time duration.
  • Generate dynamic action_list base on input account currencies (self.TI_train.all_currency_list).

2019-08-29 | anita_v2.0 code portion done | Henry.

2019-08-25 | half_tael_DQN v4.0 release | Henry.

2019-08-16 | half_tael_DQN v3.0 release | Henry.

2019-08-15 | Bugfix cost converges too quick & smooth | Henry.

  • Fixed the issued regarding Cost (loss) graph converges way too quick and smooth.

    • Wrong index for a, r in batch_memory while retrieving eval_act_index. So when replacing the reward(s), it is not the a, r being replaced, but two _close prices data at batch_memory[: , self.n_features] and batch_memory[: , self.n_features + 1] (therefore it is usually 0 or 1 as we use as type(int) during the retrieval) .

    • Changed to:

      eval_act_index = batch_memory[:, self.n_features * self.n_currencys].astype(int)
      reward = batch_memory[: , self.n_features * self.n_currencys + 1]
      

    and fixed the bug in commit d2fa6e7.

  • Partially removed hardcore code regarding self.n_features and self.n_currency.

    • CNN conv2d() part not yet done, but fixed all reshape-related setting to accept dynamic input.

2019-08-14 | Redesigned seetings of CNN | Henry, with help from Ziyu, CHEN.

  • As Steven X. is absent for three days and unresponsive on IM for four days probably due to some unexpected urgencies, I seek Ziyu for help.

  • Ziyu noticed the original strides were set to strides = [1, 2, 25, 1], combine withpadding = 'SAME' and filter = [6, 6, 1, 32] on input [-1, 3, 300, 1], which effectively "over-padded" the input. as:

    \[ W_{out} = \frac{W - F_W + 2P}{S_W} + 1 \ \Rightarrow 300 = \frac{300 - 6 + 2P}{25} + 1 \ \ \Rightarrow P = 3603 \ (\text{too many}) \ H_{out} = \frac{H - F_H + 2P}{S_H} + 1 \ \Rightarrow 3 = \frac{3 - 6 + 2P}{2} + 1 \ \ \Rightarrow P = 1.5 \ (\text{not int?}) \ \]

  • We adjusted the setting to be:

    strides = [1, 1, 1, 1]
    filter = [3, 3, 1, 32]
    
  • I also adjusted the reshape setting in l1 from 32 to 3200 to work with stride = [1, 1, 1, 1] as there will be more output:

    W_fc1 = self.weight_variable([3 * 3200, 100])
    h_pool1_flat = tf.reshape(h_pool1, [-1, 3*3200])
    

    Otherwise the line will break on:

    q_target[batch_index, eval_act_index] = reward + self.gamma * np.max(q_next, axis=1)
    
    # Before adjustment
    # q_target[batch_index, eval_act_index].shape: (32, 7)
    # q_target.shape: (3200, 7)
    # np.max(q_next, axis =1): (3200, 7)
    
  • Problem regarding cost converging too fast and smooth remains unsolved, updated cost_log.txt for future investigation.

    • After discussion with Ziyu, it is believed that the CNN part is correctly implemented, but mostly on the DQN part — however Ziyu is not particularly familiar with DQN, I will therefore continue the investigation. It is probably just a simple overfit issue as we only feeds 300 rows of train data and 300 rows of test data chronologically right after the training set, due to the power limitation of the laptop.

2019-08-13 | Refactored DQN_v2.5 to work with the trading platform | Henry.

  • Be able to trade among three currencies with hardcore setting used in RL_brain.py.
  • Problem regarding cost converging too fast and smooth remains unsolved, cost_log.txt saved for future investigation.

2019-08-11 | Bugfix and partial adjustments on DQN_v2.0, DQN_v2.5 delivered | Henry.

  • Debugged on Steven's sketch code ef6e716 with various reshape manipulations regarding self.memory, store_transition and batch_memory's slicing in feed_dict.
  • Several cosmetic on monitory print-outs.
  • Cost converges unreasonable fast and smooth, potentially overfit, need investigation.

2019-08-09 | Debug DQN_v2.0 | Henry, Steven.

  • Debug DQV_v2.0

    • solved bugs related to self.s and self.s_ for placeholder� and reshape.
    • solved bugs related to self.x and self.x_ on conv2d().
    • Work in progress on figuring out the bugs related to:
    transition = np.hstack((s, [a, r], s_))
    index = self.memory_counter % self.memory_size
    self.memory[index, :] = transition
    

2019-08-08 | Legacy Anita plot hole discovered | Henry.

  • Findings:

    • After some careful review of legacy_ref/anita folder, I found that the mapping is between personality and financial products. e.g. (letter referred Big Five Personality Traits)
      • A persona with high E and low N is good for small cap investment.
      • A person with high C, high E, low A, low N is good for foreign exchange investment.
    • There are also many disparities between the presentation slides and the metrics spreadsheet. e.g.
      • Slides indicate "Momentum Investing (med-high c, high e, high a)," but OCEAN value being 41.25, 40, 36.875, 36.25, and 35 respectively. Where the "mid-high C" is higher than the "high E" and "high A."
      • Slide indicate "Income Investing (medium-high e, high n)," but OCEAN value being 36.25, 35, 30, 30, and 32.5. Where the "mid-high E" is in fact the lowest value among five, and the supposedly "high N" ranks only among middle.
  • Conclusion: Thus, this is essentially useless to our model as it cannot evaluate if a trade_action fits a given personality of not.

  • Solution: My thinking is I will discard all Anita legacy and use some technical/fundamental analysis indicators to evaluate the "suitableness between a trade_action and given indicator" and therefore influent the reward. How a personality is defined by the indicators will left to future development.

2019-08-01 | Delivered half_tael_v2.0 running on DQN v2.0 | Henry.

  • Implemented balance_protection feature on trade_interface.py. If the balance of sell currency is not enough to execute the requested trade, such trade will be canceled. The trade log will mark such trade as "failed." (commit #b735aff)
  • Discussed with Steven on the action update policy, decided the model does not need to know if an action is actually executed since the NN design will understand that at this state the x action will have bad reward (since equal balance will result in a reward of -1).
  • Delivered half_tael_v2.0 by commit #6a051da, Still hardcored to GBP due to the fact that DQN v1.0 only supports two-currency. Thus the non-base_currency is set manually. Will automate such part when refactoring with DQN v2.5 to avoid reengineering.
...
####################game over####################
##### Displaying information regarding account "Initial_Checkout_Review (episode: 2)". #####

	record_from:                  2018-04-13T18:30:00.000000000Z
	record_to:                    2018-04-16T09:29:00.000000000Z
	request_interval:             M1
	record_rows:                  889

	trade_log_len:                2
	USD:                          0
	EUR:                          100000.0
	GBP:                          0

##### The information of account "Initial_Checkout_Review (episode: 2)" has been successfully displayed. #####

##### Displaying information regarding account "End_Checkout_Review (episode: 2)". #####

	record_from:                  2018-04-13T18:30:00.000000000Z
	record_to:                    2018-04-16T09:29:00.000000000Z
	request_interval:             M1
	record_rows:                  889

	trade_log_len:                293
	USD:                          0
	EUR:                          100025.13121083906
	GBP:                          0.0

##### The information of account "End_Checkout_Review (episode: 2)" has been successfully displayed. #####
...

2019-07-31 | Starting to refactor DQN v1.0 | Henry.

  • Till 30ec22c, a understanding of DQN v1.0 is built.
  • Bug fix on account cumulation with execute_trade() from trade_interface.py.
  • Update hardcore setting (n_features = 300, record length to 4800 etc, currency as EUR and GBP) with relatively more universal adaptability.
  • Work in progress on commit #0e0b676, as a redesign of exception handling on currency_balance[_sell_currency] < 0 is needed.
    • Ask Steven if the model need to know that some of its actions are not executed due to the balance issue.

2019-07-30 | Finished basic DQN learning | Henry.

  • Finished most DQN part (4.3, up to date with what DQN v1.0 uses).

2019-07-29 | Dev branches base on half_tael_v1.0 | Henry.

2019-07-26 | Initial commit for trial DQN between two currency | Steven, Henry.

2019-07-25 | Draft contributors' guideline for the project | Henry.

2019-07-24 | Discussed merging Steven's experimental DQN code with Henry's trading environment code | Henry, Steve.

  • Discussed the design and concern of merging Steven's experimental DQN code with Henry's trading environment code, particularly in:
    • How to support trading between multiple currencies (> 2) while making the machine realize some _close value is in the same time.
    • Possibility of using vector as first layer nodes in ANN/RNN design.
    • How to deal with missing np.nan in _close columns.
      • Increase request_interval from M1 to M5.
      • Fill in np.nan cell gradual increment/decrement according to non-empty neighborhood cells, while setting _volume to 0.

2019-07-24 | Drafted User Manual for trade_interface.py.md, implemented checkout_all_in() method | Henry.

  • Drafted User Manual for trade_interface.py.md with demo code available at train_interface_demo.py.

  • Implemented checkout_all_in() method in trade_interface.py to checkout all currency(s) in account to a particular currency (e.g. USD).

  • Debugged with Steven on his trial DQN model.

    ##### Displaying information regarding account "End_Checkout_Review". #####
    
    	record_from:                  2019-01-01T22:00:00.000000000Z
    	record_to:                    2019-01-01T23:59:00.000000000Z
    	request_interval:             M1
    	record_rows:                  118
    
    	trade_log_len:                9
    	USD:                          68536.17872218802
    	JPY:                          0.0
    	GBP:                          0.0
    
    ##### The information of account "End_Checkout_Review" has been successfully displayed. #####
    

2019-07-23 | Implemented custom exceptions handling, and stand alone training input portal | Henry.

  • Now all input should goes to — or in a form which is similar to — train_interface.py with the login info saved in config.py

  • Custom exceptions handling implemented, e.g.

    During self.get_arena()
    	<class 'trade_interface.OI_Onanda_Error'> is raised due to: {"errorMessage":"Insufficient authorization to perform request."}
    
    During self.get_currency_pairs()
    	<class 'trade_interface.TI_Account_Error'> is raised due to: No currency pair(s) between ('USD', 'JAY') from Oanda
    
    During self.account_input_eval()
    	<class 'trade_interface.TI_Account_Error'> is raised as: Invalid Oanda granularity input, self.request_interval: H20.
    
    During self.account_input_eval()
    	<class 'trade_interface.TI_Account_Error'> is raised as: Invalid account input, self.currency_balance['USD'] must be >= 0 (currently -10).
    
    During self.market_LUT()
    	<class 'trade_interface.TI_Market_LUT_Error'> is raised due to: Invalid time input: 2019-01-01T22:30:20.000000000Z
    
    During self.execute_trade()
    	<class 'trade_interface.TI_Market_LUT_Error'> is raised as: Time input: 2019-01-01T22:03:00.000000000Z returns np.nan
    
    During self.execute_trade()
    	<class 'trade_interface.TI_Execution_Error'> is raised as: USB or GBP is(are) not in ['USD', 'JPY', 'GBP']
    
    During self.execute_trade()
    	<class 'trade_interface.TI_Execution_Error'> is raised as: USD balance < 0 after trade action #0 (currently -127412000.00000001).
    
    During self.execute_trade()
    	<class 'trade_interface.TI_Execution_Error'> is raised as: _time 2019-01-01T22:29:00.000000000Z is earlier than pervious action's trade_time 2019-01-01T22:30:00.000000000Z in log.
    
    During self.account_input_eval()
    	<class 'trade_interface.TI_Account_Error'> is raised as: self.from_time 2019-01-01T00:00:00Z is earlier than self.to_time 2018-01-02T00:00:00Z.
    
  • Add feature to retrieve one trade action by action_id from trade_log.

2019-07-22 | Fully supports trading among multiple currency | Henry.

  • Bug fixed for perviously mentioned commit #8248b6f, trading among multiple currency is now fully supported (commit #443e4d1).

    ##### Displaying information regarding account "dev_arena_test". #####
    
    	record_from:                  2019-01-01T22:00:00.000000000Z
    	record_to:                    2019-01-01T23:59:00.000000000Z
    	request_interval:             M1
    	record_rows:                  118
    
    	trade_log_len:                7
    	USD:                          49986.70879394646
    	JPY:                          46692.75
    	GBP:                          50034.09294861774
    
    ##### The information of account "dev_arena_test" has been successfully displayed. #####
    
  • Support for trade_unit_in_buy_currency is implemented (commit #49e1f01).

  • Readable trade_log_review() is implemented, now each trade action is expressed in natural language rather than pure JSON.

    #### Displaying the READABLE trade log of account "dev_arena_test" ####
            ......
    		action_id:               5
    		trade_time:              2019-01-01T23:05:00.000000000Z
    		Trade Decision:          Sold 0.547006053533659 USD for 60 JPY
    		Sell Currency Balance:   50056.70879394646 USD
    		Buy Currency Balance:    39016.06 JPY
    
    
    		action_id:               6
    		trade_time:              2019-01-01T23:55:00.000000000Z
    		Trade Decision:          Sold 70 USD for 7676.6900000000005 JPY
    		Sell Currency Balance:   49986.70879394646 USD
    		Buy Currency Balance:    46692.75 JPY
    
    #### The READABLE trade log of account "dev_arena_test" has been successfully displayed ####
    

2019-07-19 | Refactored trading interface to handle trading among multiple currency (Bug-fixing in progress) | Henry.

  • Refactored the trade_interface.py to handle multiple currency.

    The requested ARENA record has been successfully exported.
    
    	file path:      ./arena_data/USD_JPY_GBP_2019-01-01T00:00:00_2019-01-02T00:00:00_M1.csv
    	currency pair:  ['USD', 'JPY', 'GBP']
    	from:           2019-01-01T00:00:00Z
    	to:             2019-01-02T00:00:00Z
    	interval:       M1
    	total rows:     118
    
  • Updated oanda_interface.py to wrap DataFrame return into a custom class Oanda_Record, so that when passed to other method info regarding such record shall preserve.

  • Setting goals and time for next two scrum meetings.

2019-07-18 | Developed internal trading interface for model testing | Henry.

  • Developed a Trade_Interface class to regulate allowed trading behavior and review portal:

    • Behaviors: short, long.
    • Review: account, trade log.
    Account dev_test is built.
    	currency_A:                   USD
    	currency_B:                   JPY
    	record_from:                  2018-01-01T22:00:00.000000000Z
    	record_to:                    2018-06-29T20:59:00.000000000Z
    	currency_A_balance:           9987.859210202378
    	currency_B_balance:           11364.3
    	trade_log_len:                4
    
    action_id:               0
    			trade_time:              2018-01-01T22:02:00.000000000Z
    			trade_type:              short
    			trade_price:             112.676
    			trade_currency:          JPY
    			trade_unit:              2000
    			currency_A_balance:      9982.249991124996
    			currency_B_balance:      12000
    
  • Marked places which can be improved in future (exception-handling, decorator log generation).

2019-07-17 | Developed wrapper functions output pricing record | Henry.

  • Developed a set of wrapper functions in oanda_interface.py, which can interact with oandapyV20 API and output pricing record according to user requested currency pair, start time, end time, interval.

  • Output is available in both DataFrame and CSV file with command line confirmation on both request and export stage:

    REQUEST: v3/instruments/USD_JPY/candles InstrumentsCandles {'granularity': 'H1', 'includeFirst': True, 'from': '2018-01-01T00:00:00Z', 'to': '2018-01-21T20:00:00Z'}
    REQUEST: v3/instruments/USD_JPY/candles InstrumentsCandles {'granularity': 'H1', 'includeFirst': True, 'from': '2018-01-21T20:00:00Z', 'to': '2018-02-11T16:00:00Z'}
    ...
    REQUEST: v3/instruments/USD_JPY/candles InstrumentsCandles {'granularity': 'H1', 'includeFirst': True, 'from': '2018-12-21T04:00:00Z', 'to': '2018-12-31T23:59:59Z'}
    
    The requested record has been successfully exported.
    	file path:      ./dummy_data/USD_JPY_2018-01-01T00:00:00_2018-12-31T23:59:59_H1.csv
    	currency pair:  USD_JPY
    	from:           2018-01-01T00:00:00Z
    	to:             2018-12-31T23:59:59Z
    	interval:       H1
    	total rows:     6217
    
  • Experienced with commit-message-emoji.

2019-07-11 | Finished Q-learning courses | Henry.

  • Finished the Q-learning section of the Morvan course.
  • Started the DQN section.
  • Hand over the pervious project to be fully committed on this one.