Giter Site home page Giter Site logo

tonyabell / mytrades.analytics Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gregkalapos/mytrades.analytics.fsharp

0.0 2.0 0.0 46 KB

myTrades.Analytics is an open source .NET library targeting netstandard1.6. The library provides technical analysis for financial instruments. It is written in F#, but can be consumed from any .NET compatible programming language.

F# 100.00%

mytrades.analytics's Introduction

myTrades.Analytics

A .NET library for technical analysis

myTrades.Analytics is an open source .NET library targeting netstandard1.6. The library provides technical analysis for financial instruments. It is written in F#, but can be consumed from any .NET compatible programming language.

API Overview

Every indicator gets one of these types as a paramter:

  • seq<Quote> (If it needs a Value and a Date for the calculation)
  • seq<OHCLWithDate> (If it needs a date and one of the OHCL Values for calculation)

And returns:

  • seq<Quote> which contains the date and the value for the indicator

Currently implemented indicators:

  • Simple Moving Avg
  • RSI
  • William's %R
  • Ultimate Oscillator (wip)

These are the types passed and returnd to/from the functions:

type Quote = { Value: decimal; Date: System.DateTime }     
type OHCL = { Open: decimal; High: decimal; Close: decimal; Low: decimal } 
type OHCLWithDate = { OHCL: OHCL; Date: System.DateTime }

Calculate SMA

open System 
open MyTrades.Analytics 
open MovingAverage 
 
[<EntryPoint>] 
let main argv = 
        let prices = [ {Value = 3m  ; Date =new DateTime(2015, 03, 1)}; 
                       {Value = 4m  ; Date =new DateTime(2015, 03, 2)}; 
                       {Value = 5m  ; Date =new DateTime(2015, 03, 3)}; 
                       {Value = 6m  ; Date =new DateTime(2015, 03, 4)}; 
                       {Value = 7m  ; Date =new DateTime(2015, 03, 5)}; 
                       {Value = 6m  ; Date =new DateTime(2015, 03, 6)}; 
                       {Value = 5m  ; Date =new DateTime(2015, 03, 7)}; 
                       {Value = 9m  ; Date =new DateTime(2015, 03, 8)} ]; 
 
        let smas = SimpleMovingAverage prices 5

Calculate RSI

open System 
open MyTrades.Analytics 
open Rsi 
 
[<EntryPoint>] 
let main argv = 
        let prices  =//populate prices seq<Quote> 
        let rsi = Rsi.Rsi prices 14; 

Calculate William %R

open System 
open MyTrades.Analytics 
open WilliamsPR 
 
[<EntryPoint>] 
let main argv = 
        let prices  =//populate prices seq<Quote> 
        let williams = WilliamsPR prices 14

Backtesting

The point of technical analysis is to give buy and sell signals. The back-testing functions in myTrades.Analytics basically looks for buy and sell signals and calculate the return of the transactions created based on the signals on the input data, which is typically a historical data for a given stock.

The return type of every back-testing function is:

type BacktestingResult = { Transactions: seq<TransactionQuote>; ResultInPercent: double } 

where TransactionQuote is:

type TransactionQuote = 
    | Buy of Quote 
    | Sell of Quote * double

Meaning the ResultInPercent stores the overall gain or loss and the the second item of the tuple in the TransactionQuote in Sell case stores the result of every sell transaction.

Backtesting RSI

open System  
open MyTrades.Analytics 
open MyTrades.Analytics.TestData 
 
[<EntryPoint>] 
let main argv = 
    let prices = GetBmwQuotes //Get historical data  
    let rsiData = Rsi prices 14 
    let rsiBackTesingResult = BackTestRsiWithPrice rsiData (prices |> Seq.skip 14)

Similar there are back-testing methods for the other indicators with the same parameters and the same return type.

  • BackTestMovingAverageWithPrice: Buys when SMA is in down trend and Price goes over it from below.
  • BackTestWilliamsPr: Buys when Williams %R reaches -100 and after 5 days it is still below -85 and sells when it reaches 0 and after 5 days it is still above -15. (This is till WIP)
  • BackTestRsiWithPrice: (as already discussed) buys when the RSI is below 30 and sells when it reaches 70

Repository structure

mytrades.analytics's People

Contributors

gregkalapos avatar

Watchers

James Cloos avatar Tony Abell avatar

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.