You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I variation of previous example with one change: tenors column (the X axis) is vector of strings.
If axis X is strings I expect graph to be equally spaced in X axis.
import ggplotnim
import random
import tables
import math
const paths =20const dates =80procgaussian*(rnd: varRand, mu =0.0, sigma =1.0): float=var
s =0.0
u =0.0
v =0.0while s >=1.0or s <=0.0:
u =2.0* rnd.rand(0.0..1.0) -1.0
v =2.0* rnd.rand(0.0..1.0) -1.0
s = (u * u) + (v * v)
let x = u *sqrt(-2.0*ln(s) / s)
return (mu + (sigma * x))
proccreateDataFrame(): DataFrame=const sigma =0.10var rnd =initRand(124325)
var data: OrderedTable[string, seq[Value]]
var simPath =newSeq[Value](dates)
for j in0..<paths:
simPath[0] =%~100.0for i in1..<dates:
simPath[i] =%~(simPath[i-1].toFloat() *exp(-0.5* sigma^2+ sigma *gaussian(rnd)))
data["path"&$(j +1)] = simPath
var tenors =newSeq[Value](dates)
for i in0..<dates:
tenors[i] =%~ ("t"&$i)
data["tenors"] = tenors
toDf(data)
let df =createDataFrame()
var g =ggplot(df)
for i in1..paths:
g = g +geom_line(aes(y ="path"&$i, x ="tenors"))
g +ggsave("test1.pdf")
The text was updated successfully, but these errors were encountered:
I variation of previous example with one change:
tenors
column (the X axis) is vector of strings.If axis X is strings I expect graph to be equally spaced in X axis.
The text was updated successfully, but these errors were encountered: