Documentation
¶
Index ¶
- Constants
- func Abs(b int) int
- func Max(i, j int) int
- func Min(i, j int) int
- func Pow(i, j int) int
- type Analysis
- type AverageProfitAnalysis
- type BuyAndHoldAnalysis
- type Candle
- type DecreaseRule
- type IncreaseRule
- type Indicator
- func NewAverageGainsIndicator(indicator Indicator, window int) Indicator
- func NewAverageLossesIndicator(indicator Indicator, window int) Indicator
- func NewCCIIndicator(ts *TimeSeries, window int) Indicator
- func NewClosePriceIndicator(series *TimeSeries) Indicator
- func NewConstantIndicator(constant float64) Indicator
- func NewCrossIndicator(upper, lower Indicator) Indicator
- func NewCumulativeGainsIndicator(indicator Indicator, window int) Indicator
- func NewCumulativeLossesIndicator(indicator Indicator, window int) Indicator
- func NewDifferenceIndicator(minuend, subtrahend Indicator) Indicator
- func NewEMAIndicator(indicator Indicator, window int) Indicator
- func NewFixedIndicator(vals ...float64) Indicator
- func NewHighPriceIndicator(series *TimeSeries) Indicator
- func NewLowPriceIndicator(series *TimeSeries) Indicator
- func NewMACDHistogramIndicator(macdIdicator Indicator, signalLinewindow int) Indicator
- func NewMACDIndicator(baseIndicator Indicator, shortwindow, longwindow int) Indicator
- func NewMeanDeviationIndicator(indicator Indicator, window int) Indicator
- func NewOpenPriceIndicator(series *TimeSeries) Indicator
- func NewPercentChangeIndicator(indicator Indicator) Indicator
- func NewRelativeStrengthIndexIndicator(indicator Indicator, timeframe int) Indicator
- func NewRelativeStrengthIndicator(indicator Indicator, timeframe int) Indicator
- func NewRelativeVigorIndexIndicator(series *TimeSeries) Indicator
- func NewRelativeVigorSignalLine(series *TimeSeries) Indicator
- func NewSimpleMovingAverage(indicator Indicator, window int) Indicator
- func NewTypicalPriceIndicator(series *TimeSeries) Indicator
- func NewVolumeIndicator(series *TimeSeries) Indicator
- type LogTradesAnalysis
- type NumTradesAnalysis
- type Order
- type OrderSide
- type OverIndicatorRule
- type PercentGainAnalysis
- type PeriodProfitAnalysis
- type Position
- func (p *Position) CostBasis() big.Decimal
- func (p *Position) Enter(order *Order)
- func (p *Position) EntranceOrder() *Order
- func (p *Position) Exit(order *Order)
- func (p *Position) ExitOrder() *Order
- func (p *Position) ExitValue() big.Decimal
- func (p *Position) IsClosed() bool
- func (p *Position) IsLong() bool
- func (p *Position) IsNew() bool
- func (p *Position) IsOpen() bool
- func (p *Position) IsShort() bool
- type ProfitableTradesAnalysis
- type Rule
- func And(r1, r2 Rule) Rule
- func NewCrossDownIndicatorRule(upper, lower Indicator) Rule
- func NewCrossUpIndicatorRule(upper, lower Indicator) Rule
- func NewPercentChangeRule(indicator Indicator, percent float64) Rule
- func NewPositionNewRule() Rule
- func NewPositionOpenRule() Rule
- func NewStopLossRule(series *TimeSeries, lossTolerance float64) Rule
- func Or(r1, r2 Rule) Rule
- type RuleStrategy
- type StopLossRule
- type Strategy
- type TimePeriod
- type TimeSeries
- type TotalProfitAnalysis
- type TradingRecord
- func (this *TradingRecord) CurrentPosition() *Position
- func (this *TradingRecord) Enter(price, amount, feePercentage big.Decimal, security string, time time.Time)
- func (this *TradingRecord) Exit(price, amount, feePercentage big.Decimal, security string, time time.Time)
- func (this *TradingRecord) LastTrade() *Position
- type UnderIndicatorRule
Constants ¶
const SimpleDateFormat = "01/02/2006"
const SimpleDateTimeFormat = "01/02/2006T15:04:05"
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Analysis ¶
type Analysis interface {
Analyze(*TradingRecord) float64
}
type AverageProfitAnalysis ¶
type AverageProfitAnalysis string
func (AverageProfitAnalysis) Analyze ¶
func (apa AverageProfitAnalysis) Analyze(record *TradingRecord) float64
type BuyAndHoldAnalysis ¶
type BuyAndHoldAnalysis struct { *TimeSeries StartingMoney float64 }
func (BuyAndHoldAnalysis) Analyze ¶
func (baha BuyAndHoldAnalysis) Analyze(record *TradingRecord) float64
type Candle ¶
type Candle struct { Period TimePeriod OpenPrice big.Decimal `json:",string"` ClosePrice big.Decimal `json:",string"` MaxPrice big.Decimal `json:",string"` MinPrice big.Decimal `json:",string"` Volume big.Decimal `json:",string"` TradeCount uint }
func NewCandle ¶
func NewCandle(period TimePeriod) (c *Candle)
type DecreaseRule ¶
type DecreaseRule struct {
Indicator
}
func (DecreaseRule) IsSatisfied ¶
func (dr DecreaseRule) IsSatisfied(index int, record *TradingRecord) bool
type IncreaseRule ¶
type IncreaseRule struct {
Indicator
}
func (IncreaseRule) IsSatisfied ¶
func (ir IncreaseRule) IsSatisfied(index int, record *TradingRecord) bool
type Indicator ¶
func NewAverageGainsIndicator ¶
Returns a new average gains indicator, which returns the average gains up until that index. @param price indicator should not be > 1 derivation removed from a timeseries, i.e., a ClosePriceIndicator, VolumeIndicator, etc
func NewAverageLossesIndicator ¶
Returns a new average losses indicator, which returns the average losses up until that index. @param price indicator should not be > 1 derivation removed from a timeseries, i.e., a ClosePriceIndicator, VolumeIndicator, etc
func NewCCIIndicator ¶
func NewCCIIndicator(ts *TimeSeries, window int) Indicator
Returns a new Commodity Channel Index Indicator http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:commodity_channel_index_cci
func NewClosePriceIndicator ¶
func NewClosePriceIndicator(series *TimeSeries) Indicator
func NewConstantIndicator ¶
func NewCrossIndicator ¶
Returns a new CrossIndicator, which, given an index, determines whether a lower indicator has crossed an upper one
func NewDifferenceIndicator ¶
func NewEMAIndicator ¶
Returns a new Exponential Moving Average Calculator http://www.investopedia.com/terms/e/ema.asp
func NewFixedIndicator ¶
func NewHighPriceIndicator ¶
func NewHighPriceIndicator(series *TimeSeries) Indicator
func NewLowPriceIndicator ¶
func NewLowPriceIndicator(series *TimeSeries) Indicator
func NewMACDHistogramIndicator ¶
Returns a new Moving Average Convergence-Divergence histogram incicator, the result of which is the macd indicator minus it's @param signalLinewindow EMA http://stockcharts.com/school/doku.php?id=chart_school:technical_indicators:macd-histogram
func NewMACDIndicator ¶
Returns a new Moving Average Convergence-Divergence indicator http://www.investopedia.com/terms/m/macd.asp
func NewMeanDeviationIndicator ¶
Returns a new mean deviation indicator
func NewOpenPriceIndicator ¶
func NewOpenPriceIndicator(series *TimeSeries) Indicator
func NewRelativeVigorIndexIndicator ¶
func NewRelativeVigorIndexIndicator(series *TimeSeries) Indicator
func NewRelativeVigorSignalLine ¶
func NewRelativeVigorSignalLine(series *TimeSeries) Indicator
func NewSimpleMovingAverage ¶
func NewTypicalPriceIndicator ¶
func NewTypicalPriceIndicator(series *TimeSeries) Indicator
func NewVolumeIndicator ¶
func NewVolumeIndicator(series *TimeSeries) Indicator
type LogTradesAnalysis ¶
func (LogTradesAnalysis) Analyze ¶
func (lta LogTradesAnalysis) Analyze(record *TradingRecord) float64
type NumTradesAnalysis ¶
type NumTradesAnalysis string
func (NumTradesAnalysis) Analyze ¶
func (nta NumTradesAnalysis) Analyze(record *TradingRecord) float64
type Order ¶
type OverIndicatorRule ¶
func (OverIndicatorRule) IsSatisfied ¶
func (this OverIndicatorRule) IsSatisfied(index int, record *TradingRecord) bool
type PercentGainAnalysis ¶
type PercentGainAnalysis struct{}
func (PercentGainAnalysis) Analyze ¶
func (pga PercentGainAnalysis) Analyze(record *TradingRecord) float64
type PeriodProfitAnalysis ¶
func (PeriodProfitAnalysis) Analyze ¶
func (ppa PeriodProfitAnalysis) Analyze(record *TradingRecord) float64
type Position ¶
type Position struct {
// contains filtered or unexported fields
}
A pair of two Order objects
func NewPosition ¶
func (*Position) EntranceOrder ¶
type ProfitableTradesAnalysis ¶
type ProfitableTradesAnalysis string
func (ProfitableTradesAnalysis) Analyze ¶
func (pta ProfitableTradesAnalysis) Analyze(record *TradingRecord) float64
type Rule ¶
type Rule interface {
IsSatisfied(index int, record *TradingRecord) bool
}
func NewCrossUpIndicatorRule ¶
func NewPercentChangeRule ¶
func NewPositionNewRule ¶
func NewPositionNewRule() Rule
func NewPositionOpenRule ¶
func NewPositionOpenRule() Rule
func NewStopLossRule ¶
func NewStopLossRule(series *TimeSeries, lossTolerance float64) Rule
Returns a new stop loss rule based on a timeseries and a loss tolerance The loss tolerance should be a number between -1 and 1, where negative values represent a loss and vice versa.
type RuleStrategy ¶
func (RuleStrategy) ShouldEnter ¶
func (this RuleStrategy) ShouldEnter(index int, record *TradingRecord) bool
func (RuleStrategy) ShouldExit ¶
func (this RuleStrategy) ShouldExit(index int, record *TradingRecord) bool
type StopLossRule ¶
type StopLossRule struct { Indicator // contains filtered or unexported fields }
func (StopLossRule) IsSatisfied ¶
func (slr StopLossRule) IsSatisfied(index int, record *TradingRecord) bool
type Strategy ¶
type Strategy interface { ShouldEnter(index int, record *TradingRecord) bool ShouldExit(index int, record *TradingRecord) bool }
type TimePeriod ¶
func NewTimePeriod ¶
func NewTimePeriod(start, end time.Time) TimePeriod
func NewTimePeriodD ¶
func NewTimePeriodD(start time.Time, period time.Duration) TimePeriod
func Parse ¶
func Parse(timerange string) (tr TimePeriod, err error)
Support SimpleDateTimeFormat:SimpleDateTimeFormat SimpleDateTimeFormat: (to now) SimpleDateFormat: SimpleDateFormat:SimpleDateFormat
func (TimePeriod) Advance ¶
func (tp TimePeriod) Advance(iterations int) TimePeriod
func (TimePeriod) Format ¶
func (tp TimePeriod) Format(layout string) string
func (TimePeriod) Length ¶
func (tp TimePeriod) Length() time.Duration
func (TimePeriod) Since ¶
func (tp TimePeriod) Since(other TimePeriod) time.Duration
func (TimePeriod) String ¶
func (tp TimePeriod) String() string
type TimeSeries ¶
type TimeSeries struct {
Candles []*Candle
}
func NewTimeSeries ¶
func NewTimeSeries() (t *TimeSeries)
func RandomTimeSeries ¶
func RandomTimeSeries(size int) *TimeSeries
func (*TimeSeries) AddCandle ¶
func (ts *TimeSeries) AddCandle(candle *Candle) bool
func (*TimeSeries) LastCandle ¶
func (ts *TimeSeries) LastCandle() *Candle
func (*TimeSeries) LastIndex ¶
func (ts *TimeSeries) LastIndex() int
type TotalProfitAnalysis ¶
type TotalProfitAnalysis float64
func (TotalProfitAnalysis) Analyze ¶
func (tps TotalProfitAnalysis) Analyze(record *TradingRecord) float64
type TradingRecord ¶
type TradingRecord struct { Trades []*Position // contains filtered or unexported fields }
func NewTradingRecord ¶
func NewTradingRecord() (t *TradingRecord)
func (*TradingRecord) CurrentPosition ¶
func (this *TradingRecord) CurrentPosition() *Position
func (*TradingRecord) LastTrade ¶
func (this *TradingRecord) LastTrade() *Position
type UnderIndicatorRule ¶
func (UnderIndicatorRule) IsSatisfied ¶
func (this UnderIndicatorRule) IsSatisfied(index int, record *TradingRecord) bool
Source Files
¶
- analysis.go
- candle.go
- indicator.go
- indicator_average.go
- indicator_basic.go
- indicator_cci.go
- indicator_constant.go
- indicator_cross.go
- indicator_difference.go
- indicator_fixed.go
- indicator_gains.go
- indicator_mean_deviation.go
- indicator_moving_average.go
- indicator_relative_strength.go
- indicator_relative_vigor_index.go
- math.go
- order.go
- position.go
- rule.go
- rule_cross.go
- rule_increase_decrease.go
- rule_position.go
- rule_stop.go
- strategy.go
- testutils.go
- timeperiod.go
- timeseries.go
- tradingrecord.go