quant

package
v0.0.0-...-4fdae40 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 5 Imported by: 0

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

Examples

Constants

View Source
const (
	DateFormat = "2006-01-02"

	Buy  = 1
	Sell = 0
)

Variables

This section is empty.

Functions

func AnnualizedGain

func AnnualizedGain(totalGain float64, startDate time.Time, endDate time.Time) float64

AnnualizedGain will return the annualized gain given a totalGain achieved between the startDate and endDate.

func Init

func Init(appNameInit string)

func MA

func MA(length int, biasStart bool, dataSlices ...[]float64) []float64

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

func MultiplySlice(scale float64, dataSlice []float64) []float64

multiplySlice will multiply the input slice values by the provided scale factor and return the resulting slice.

func MultiplySliceGated

func MultiplySliceGated(scale float64, dataSlice []float64, gate []int, gateValue int) []float64

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

func MultiplySlices(dataSlices ...[]float64) []float64

multiplySlices will perform a pointwise product of all inputs slices and return the resulting slice.

func OffsetSlice

func OffsetSlice(offset float64, dataSlice []float64) []float64

offsetSlice will add an offset to all values in the input slice and return the resulting slice.

func ReciprocolSlice

func ReciprocolSlice(dataSlice []float64) []float64

reciprocolSlice will perform a pointwise reciprical of the input slice and return the resulting slice.

func SlicesAreEqualLength

func SlicesAreEqualLength(dataSlices ...[]float64) error

slicesAreEqualLength returns an error if the input slices are not of the same length.

func SumSlices

func SumSlices(dataSlices ...[]float64) []float64

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

func TradeOnPrice(delay int, close, price, buyLevel, sellLevel []float64) []int

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.

Types

type Results

type Results struct {
	AnnualizedGain  float64
	TotalGain       float64
	TradeHistory    string
	TradeMA         []int
	TradeGainVsTime []float64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL