Documentation
¶
Overview ¶
Example (TradeGain) ¶
// make columns line up by using sel instead of Sell, and trade____ instead of trade. sel := Sell trade____ := []int{sel, sel, sel, Buy, Buy, Buy, sel, sel} close := []float64{1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0, 2.0} openn := []float64{1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 2.0, 2.0} issue := downloader.Issue{} issue.DatasetAsColumns.AdjClose = close issue.DatasetAsColumns.AdjOpen = openn issue.DatasetAsColumns.Date = []time.Time{ time.Date(2022, 1, 1, 0, 0, 0, 0, time.UTC), time.Date(2022, 1, 2, 0, 0, 0, 0, time.UTC), time.Date(2022, 1, 3, 0, 0, 0, 0, time.UTC), time.Date(2022, 1, 4, 0, 0, 0, 0, time.UTC), time.Date(2022, 1, 5, 0, 0, 0, 0, time.UTC), time.Date(2022, 1, 6, 0, 0, 0, 0, time.UTC), time.Date(2022, 1, 7, 0, 0, 0, 0, time.UTC), time.Date(2022, 1, 8, 0, 0, 0, 0, time.UTC)} issue.Symbol = "test" _, gain, tradeG := TradeGain(2, trade____, issue) fmt.Printf("%5.2f %+v\n", gain, tradeG) trade____ = []int{sel, sel, sel, sel, Buy, Buy, Buy, sel} _, gain, tradeG = TradeGain(2, trade____, issue) fmt.Printf("%5.2f %+v\n", gain, tradeG) trade____ = []int{sel, sel, sel, sel, sel, Buy, Buy, Buy} _, gain, tradeG = TradeGain(2, trade____, issue) fmt.Printf("%5.2f %+v\n", gain, tradeG)
Output: 2.00 [1 1 1 1 1 2 2 2] 2.00 [1 1 1 1 1 2 2 2] 1.00 [1 1 1 1 1 1 1 1]
Index ¶
- Constants
- func AnnualizedGain(totalGain float64, startDate time.Time, endDate time.Time) float64
- func Init(appNameInit string)
- func MA(length int, biasStart bool, dataSlices ...[]float64) []float64
- func MultiplySlice(scale float64, dataSlice []float64) []float64
- func MultiplySliceGated(scale float64, dataSlice []float64, gate []int, gateValue int) []float64
- func MultiplySlices(dataSlices ...[]float64) []float64
- func OffsetSlice(offset float64, dataSlice []float64) []float64
- func ReciprocolSlice(dataSlice []float64) []float64
- func SlicesAreEqualLength(dataSlices ...[]float64) error
- func SumSlices(dataSlices ...[]float64) []float64
- func TradeGain(delay int, trade []int, dlIssue downloader.Issue) (tradeHistory string, gain float64, tradeGain []float64)
- func TradeOnPrice(delay int, close, price, buyLevel, sellLevel []float64) []int
- type Results
Examples ¶
Constants ¶
const ( DateFormat = "2006-01-02" Buy = 1 Sell = 0 )
Variables ¶
This section is empty.
Functions ¶
func AnnualizedGain ¶
AnnualizedGain will return the annualized gain given a totalGain achieved between the startDate and endDate.
func MA ¶
MA is the moving average of the dataSlices. If biasStart==true the initial points of the series are filled with the value of the MA on the first point after length points.
func MultiplySlice ¶
multiplySlice will multiply the input slice values by the provided scale factor and return the resulting slice.
func MultiplySliceGated ¶
multiplySlice will perform multiply the input slice values by the provided scale factor, but only when the provided gate[i] == gateValue and return the resulting slice.
func MultiplySlices ¶
multiplySlices will perform a pointwise product of all inputs slices and return the resulting slice.
func OffsetSlice ¶
offsetSlice will add an offset to all values in the input slice and return the resulting slice.
func ReciprocolSlice ¶
reciprocolSlice will perform a pointwise reciprical of the input slice and return the resulting slice.
func SlicesAreEqualLength ¶
slicesAreEqualLength returns an error if the input slices are not of the same length.
func SumSlices ¶
sumSlices will perform a pointwise sum of all inputs slices and return the resulting slice.
func TradeGain ¶
func TradeGain(delay int, trade []int, dlIssue downloader.Issue) (tradeHistory string, gain float64, tradeGain []float64)
TradeGain takes in input slice trade with values Buy/Sell, and after delay number of points, applies the Buy/Sell signals to dlIssue to proces a tradeHistory, gain (total gain), and tradeGain (accumulated gain/loss at each point).
func TradeOnPrice ¶
Trade delays delay number of points, then compares price to the buyLevel and sellLevel, and returns an output slice indicating Buy or Sell at each point. Note that Sell is returned for the first delay number of points.