Giter VIP home page Giter VIP logo

samurai's Introduction

samurai

Samurai is a GUI for TA4J. It's supposed to make it easier for you to get insights in how to improve your trading strategy. You will be able to use all the TA4J built-in and custom indicators to create your strategies. When you have written a strategy, you run it over a dataprovider to see how it would have traded. At some point, this will also support automated trading.

Note that this is still a work in progress application and it is not yet functional enough to be used.

EDIT: you know those people who start projects and never finish them? I'm one of those people. I'm not finishing this project, but you can do whatever you want with it

Installation

  1. This library requires a dependency which isn't on maven central. It's called xtendfx and you can find it here: https://github.com/svenefftinge/xtendfx
  2. You'll also need to get my forked version of ta4j. The official version will not work (yet). You can find it here: https://github.com/sirolf2009/ta4j
  3. run
git clone https://github.com/sirolf2009/samurai.git
cd samurai/samurai
mvn install

Strategies examples

class StrategySMACrossover implements IStrategy {
	
	// we keep these two indicators as variables, so we can re-use them when we're asked what indicators we'd like to show
	// Note that the type MUST be Indicator<Decimal>
	var Indicator<Decimal> shortSma
	var Indicator<Decimal> longSma
	
	// we have two parameters for this strategy. The annotation will ensure that the user can change them in the GUI
	@Param public var shortPeriod = 5
	@Param public var longPeriod = 30

	// if this confuses you, you should read the TA4J documentation. Not mine	
	override setup(TimeSeries series) {
		val closePrice = new ClosePriceIndicator(series)

        shortSma = new SMAIndicator(closePrice, shortPeriod)
        longSma = new SMAIndicator(closePrice, longPeriod)

        val buyingRule = new CrossedUpIndicatorRule(shortSma, longSma)
        val sellingRule = new CrossedDownIndicatorRule(shortSma, longSma)
        
        return new Strategy(buyingRule, sellingRule)
	}
	
	// We want to add both our indicators to the 0th panel, which is the price panel
	override indicators(TimeSeries series) {
        return #[
        	0 -> #[shortSma, longSma]
        ]
	}
	
}
class StrategyMovingMomentum implements IStrategy {
	
	// we keep these indicators as variables, so we can re-use them when we're asked what indicators we'd like to show
	// Note that the type MUST be Indicator<Decimal>
	var Indicator<Decimal> shortEma
	var Indicator<Decimal> longEma
	var Indicator<Decimal> stochasticOscillK
	var Indicator<Decimal> macd
	var Indicator<Decimal> emaMacd
	
	// we have six parameters for this strategy. The annotation will ensure that the user can change them in the GUI
	@Param public var shortPeriod = 9
	@Param public var longPeriod = 26
	@Param public var stochPeriod = 14
	@Param public var macdShortPeriod = 9
	@Param public var macdLongPeriod = 26
	@Param public var macdSmooth = 18
	
	// if this confuses you, you should read the TA4J documentation. Not mine	
	override setup(TimeSeries series) {
        val closePrice = new ClosePriceIndicator(series)
        
        shortEma = new EMAIndicator(closePrice, shortPeriod)
        longEma = new EMAIndicator(closePrice, longPeriod)

        stochasticOscillK = new StochasticOscillatorKIndicator(series, stochPeriod)

        macd = new MACDIndicator(closePrice, macdShortPeriod, macdLongPeriod)
        emaMacd = new EMAIndicator(macd, macdSmooth)
        
        val entryRule = new OverIndicatorRule(shortEma, longEma)
                .and(new CrossedDownIndicatorRule(stochasticOscillK, Decimal.valueOf(20)))
                .and(new OverIndicatorRule(macd, emaMacd))
        
        val exitRule = new UnderIndicatorRule(shortEma, longEma)
                .and(new CrossedUpIndicatorRule(stochasticOscillK, Decimal.valueOf(80)))
                .and(new UnderIndicatorRule(macd, emaMacd))
        
        return new Strategy(entryRule, exitRule)
	}
	
	// Here we set up our indicators
	override indicators(TimeSeries series) {
        return #[
        	0 -> #[shortEma, longEma], //Our ema's should appear in the price panel, so we give them a key of 0
        	1 -> #[stochasticOscillK], //Our stoch should have it's own panel, we give it a key of 1 and don't add any other indicators
        	2 -> #[macd, emaMacd] //Our MACD and MACD EMA should both be in the same panel, we give them a key of 2
        ]
	}
	
}

Screenshots

samurai's People

Contributors

sirolf2009 avatar

Watchers

James Cloos 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.