修改代码以获得从牛市到熊市周期平滑趋势的综合数据 [英] Modify code to get synthetic data that trends smoothly from bull to bear market cycles

查看:119
本文介绍了修改代码以获得从牛市到熊市周期平滑趋势的综合数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个此类,可以生成综合外观(库存)数据,并且工作正常。但是,我想对其进行修改,以使NewPrice为 n条形生成平滑的趋势数据。

I have this class that generates synthetic looking (stock) data and it works fine. However, I want to modify it so that NewPrice generates smooth trending data for say n-bars.

我知道,如果降低波动率,价格会更平稳。但是,不确定如何保证数据上下交替出现持续趋势。正弦波看似事物,但具有看似股票的价格,即没有负价格。

I know that if I reduce the volatility, I get smoother prices. However, not sure how to guarantee that the data goes into alternating persistant trend either up/down. A sine wave looking thing, but with stock looking prices, i.e, no negative prices.

价格=趋势+先前价格+随机成分

有什么建议吗?

class SyntheticData
{
    public static double previous = 1.0;

    public static double NewPrice(double volatility, double rnd)
    {               
        var change_percent = 2 * volatility * rnd;
        if (change_percent > volatility)
            change_percent -= (2 * volatility);

        var change_amount = previous * change_percent;
        var new_price = previous + change_amount;
        previous = new_price;

        return new_price;
    }
}

Trade.previous = 100.0;
Price = Trade.NewPrice(.03, rnd.NextDouble()),


推荐答案

类似的东西就是我想要的东西

Something like this is what I was looking for:

public static double[] Sine(int n)
{
    const int FS = 64; // sampling rate

    return MathNet.Numerics.Generate.Sinusoidal(n, FS, 1.0, 20.0);
}

尽管如此,对于想要交易价格和价格的人来说,这并不直观

Although, it is not intuitive for a person that wants to deal in prices and time-based periodicity and not in mathematical functions.

https://numerics.mathdotnet.com/Generate.html

这篇关于修改代码以获得从牛市到熊市周期平滑趋势的综合数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆