Git Product home page Git Product logo

trader's Introduction

trader

The package trader provides a library/wrapper to the Alpha Vantage API provided a free or premium API key (see below). Additionally, various trading models based on historical data are provided, none of which (disclaimer) is investment advice.

Installation

You can install the package via devtools from github

devtools::install_github("shill1729/trader")

Setting up your API key in .Renviron

Register with Alpha Vantage to obtain a free API key or subscribe for a premium API key. Save these in your .Renviron file with

usethis::edit_r_environ()

and simply set in the .Renviron file the following variables:

free_api_key = "YOUR_KEY_CODE1"
premium_api_key = "YOUR_KEY_CODE2"

where the RHS is the actual key obtained from AV. The second line is not required obviously if you only plan on registering a free API key.

By default a premium key is assumed in every function that calls the AV API. In the future we will add an option to set defaults.

Examples

Here are various examples on how to use the package:

Downloading a single stock's price history

library(trader)
symbol <- "NTDOY"
s <- getPriceTimeSeries(symbol, key = "free")

# Plot the price chart
print(plot(s$adj_close, main = symbol))

# Print latest adjust close prices
print(tail(s$adj_close))

Download multiple stocks with common history

When downloading multiple stocks the data-set will go back as far as the latest common date between all assets. As of now, only adjusted close prices are available. In the future options to return any of the OHLC prices will be available.

library(trader)
symbols <- c("NTDOY", "ROKU", "TSLA")
s <- getStocks(symbols, key = "free")
print(plot(s))
print(tail(s))

Optimal log-utility investment under discrete-time stable vs Gaussian mixture returns

This function performs four tasks:

  1. Downloads a stock's prices from AV
  2. Fits a Gaussian mixture distribution and stable distribution to daily arithmetic returns.
  3. Computes a likelihood ratio test to reject one of the two fits, if possible.
  4. Computes the optimal log-utility allocation in the stock.

Returned is the optimal fraction, the long-term optimal growth rate, and the reduction fraction together with a plot of the empirical density function compared to the model densities (Gaussian mixture and stable).

library(trader)
symbol <- "NTDOY"
# Default call uses entire price history, can be changed with rollingWindow
z <- dtfm_strategy(symbol)
print(z)

trader's People

Contributors

shill1729 avatar

Stargazers

 avatar

Watchers

 avatar

trader's Issues

date_yte.R

I think there is a problem with line 11 since "bizdays::has.calendars" is not an exported object from 'namespace:bizdays'. Nico

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.