简体   繁体   English

数据表、数据集、实体框架、LINQ & Lambda 金融技术分析表达式 C#

[英]DataTables, DataSets, Entity Framework, LINQ & Lambda Expression for Financial Technical Analysis C#

this is more of an architectural question more than a specific code problem as I've hit a major block in how I am going to proceed with this project.这更像是一个架构问题,而不是一个特定的代码问题,因为我在如何继续这个项目时遇到了一个主要障碍。

I'm building a financial scanning software that filters stock picks on specific criteria, for example.例如,我正在构建一个财务扫描软件,它可以根据特定标准筛选股票。 For example if out of 8000 stocks, its closing price today is above the SMA 100 and 10 days ago the closing price is below the SMA 100, then return this stock Symbol back to me.例如,如果在 8000 只股票中,其今天的收盘价高于 SMA 100,而 10 天前的收盘价低于 SMA 100,则将此股票代码返回给我。

However, note that the SMA (Simple Moving Average) is calculated with the last 100 days of data in the above example, but it could be that we could change the 100 days for lets say another value, 105 or 56 - could be anything.但是,请注意,在上面的示例中,SMA(简单移动平均线)是根据最近 100 天的数据计算得出的,但我们可以将这 100 天更改为另一个值,例如 105 或 56 - 可以是任何值。

In my Database I have a table definition called EODData with a few columns, here is the definition below;在我的数据库中,我有一个名为 EODData 的表定义,其中包含几列,下面是定义;

EODData
sSymbol nvarchar(6)
mOpen money
mClose money
mHigh money
mLow money
Date datetime

The table will hold 3 years of End Of Day Data for the American Stock Exchange so that is approximately 6,264,000 rows, no problem for MS SQL 2008 R2.该表将保存美国证券交易所 3 年的日终数据,因此大约有 6,264,000 行,对于 MS SQL 2008 R2 没有问题。

Now, I'm currently using Entity Framework to retrieve data from my database, however what would be the best way to run or create my filter because the SMA must be calculated for each Symbol or underlying Stock Ticker each time a scan is performed because the 100 day variable can change.现在,我目前正在使用实体框架从我的数据库中检索数据,但是运行或创建我的过滤器的最佳方法是什么,因为每次执行扫描时都必须为每个符号或基础股票代码计算 SMA,因为100 天变量可以更改。

Should I convert from Entity Objects to a DataSet for in memory filtering etc???我应该在 memory 过滤等中从实体对象转换为数据集吗???

I've not worked with DataSets or DataTables much so I am looking for pointers.我没有过多地使用 DataSets 或 DataTables,所以我正在寻找指针。

Note that the SMA is just one of the filters, I have another algorithm that calculates the EMA (Exponential Moving Average, which is a much more complicated formula) and MACD (Moving Average Convergence Divergence).请注意,SMA 只是其中一个过滤器,我还有另一种算法可以计算 EMA(指数移动平均线,这是一个更复杂的公式)和 MACD(移动平均线收敛散度)。

Any opinions?有什么意见吗?

What about putting the calculations in the database?将计算结果放入数据库怎么样? You have your EODData table, which is great.你有你的 EODData 表,这很棒。 Create another table that is your SummaryData, something like:创建另一个作为您的 SummaryData 的表,例如:

SummaryData
stockSymbol varchar(6) -- don't need nvarchar, since AMSE doesn't have characters outside of normal English alphabet.
SMA decimal
MCDA decimal
EMA decimal

Then you can write some stored procedures that run on close of day and update this one table based on the data in your EODData table.然后,您可以编写一些在收盘时运行的存储过程,并根据 EODData 表中的数据更新这个表。 Or you could write a trigger so that each insert of the EODData table updates the summary data in your database.或者,您可以编写一个触发器,以便 EODData 表的每次插入都会更新数据库中的汇总数据。

One downside to this is that you're putting some business logic in the database.这样做的一个缺点是您将一些业务逻辑放入数据库中。 Another downside is that you will be updating statistical data on a stock symbol that you might not need to do.另一个缺点是您将更新您可能不需要做的股票代码的统计数据。 For example, if nobody ever wants to see what XYZZ did, then the calculation on it is pointless.例如,如果没有人想看看 XYZZ 做了什么,那么对其进行计算就毫无意义。

However, this second issue is mitigated by the fact that 1. you're running SPs on the server which MSSQL can optimize and 2. You can run these after hours when everyone is at home, so if it takes a little bit of time you're not affected.但是,第二个问题通过以下事实得到缓解:1.您在 MSSQL 可以优化的服务器上运行 SP;2.您可以在每个人都在家时在几个小时后运行这些,所以如果需要一点时间,您'不受影响。 (To be honest, I'd assume if they're calculations like rolling averages, min/max etc, SQL won't be that slow.) (老实说,我假设它们是滚动平均值、最小值/最大值等计算,SQL 不会那么慢。)

One upside is your queries should be wicked fast, because you could write一个好处是你的查询应该很快,因为你可以写

select stockSymbol from SummaryData where SMA > 10 you've already done the calculation. select stockSymbol from SummaryData where SMA > 10你已经完成了计算。

Another upside is that the data will only change once per day (at the close of the business day) but you might be querying several times throughout the day.另一个好处是数据每天只会更改一次(在工作日结束时),但您可能会在一天中查询多次。 For example, you want to run several different queries today for all the data up to and including yesterday.例如,您希望今天对直到昨天(包括昨天)的所有数据运行几个不同的查询。 If you run 10 queries, and your partner runs the same 10 queries, you've just done the same calculation over.如果您运行 10 个查询,而您的伙伴运行相同的 10 个查询,那么您刚刚完成了相同的计算。 (Essentially, write once, read many.) (本质上,写一次,读多次。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM