GithubHelp home page GithubHelp logo

auto-trading's Introduction

Auto-Trading

An Actor Critic Based stock trader program

Usage

python trader.py --training training_data.csv --testing testing_data.csv --output output.csv

Strategy

Use Actor Critic Algorithms (Source) to predict stock trend of tomorrow, and use simple judge policy to do action according to the predict trend.

State of Actor Critic

  • Moving average (10 days)
  • Difference of today moving average & yesterday moving average
  • Magnitude of difference of moving average: [0,1,2,3] (means fall, decline, flat, rise)

Predict Trend

(As Action of Actor Critic) (Should equal to the Magnitude of difference of moving average tomorrow) Value

  • 0: fall
  • 1: decline
  • 2: flat
  • 3: rise

Hold State

  • -1: short 1 stock
  • 0: no stock
  • 1: hold 1 stock

Action

  • 1: buy
  • 0: no action
  • -1: sold (or short)

Action Strategy

if(hold == 0):
  if(trend_of_tomorrow > 1):
    action = 1
  else:
    action = -1
elif(hold == 1):
  if(trend_of_tomorrow > 1):
    action = 0
  else:
    action = -1
else:
  if(trend_of_tomorrow < 3):
    action = 0
  else:
    action = 1

Stock Data Format

Open High Low Close
209.894836 216.427353 207.758728 216.208771
... ... ... ...

Action Type

The action should be one of these three types: 1 → means to “Buy” the stock. If you short 1 unit, you will return to 0 as the open price in the next day. If you did not have any unit, you will have 1 unit as the open price in the next day. “If you already have 1 unit, your code will be terminated due to the invalid status.“

0 → means to “NoAction”. If you have 1-unit now, hold it. If your slot is available, the status continues. If you short 1 unit, the status continues.

-1 → means to “Sell” the stock. If you hold 1 unit, your will return to 0 as the open price in the next day. If you did not have any unit, we will short 1 unit as the open price in the next day. “If you already short 1 unit, your code will be terminated due to the invalid status.“

In the final day, if you hold/short the stock, we will force your slot empty as the close price of the final day in the testing period. Finally, your account will be settled and your profit will be calculated.

Input Sample:

Output Sample:

  1. Each line in output file contains the action type which will be executed in the opening of the next day.

  2. If the testing data contains 300 lines, the output would include 299 lines. But the last day will be settled without executing the specified action, and the calculator will use the close price of the last day as the settled price.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.