用于开发交易策略的脚本语言

发布于 2024-08-22 08:58:30 字数 261 浏览 8 评论 0原文

我目前正在开发一个交易产品的组件,该组件将允许量化或策略开发人员编写自己的自定义策略。我显然不能让他们用本机编译的语言(甚至是编译为字节码以在虚拟机上运行的语言)编写这些策略,因为他们的开发/测试周期必须在几分钟左右。

到目前为止,我已经研究过 lua、python、ruby,并且非常喜欢它们,但仍然发现它们对于我的目标用户来说有点“低级”。我是否需要以某种方式编写自己的解析器+解释器来支持一种至少支持循环、简单算术、逻辑表达式评估的语言,或者你们中的任何人可能还有其他建议吗?提前致谢。

I'm currently working on a component of a trading product that will allow a quant or strategy developer to write their own custom strategies. I obviously can't have them write these strategies in natively compiled languages (or even a language that compiles to a bytecode to run on a vm) since their dev/test cycles have to be on the order of minutes.

I've looked at lua, python, ruby so far and really enjoyed all of them so far, but still found them a little "low level" for my target users. Would I need to somehow write my own parser + interpreter to support a language with a minimum of support for looping, simple arithmatic, logical expression evaluation, or is there another recommendation any of you may have? Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

野味少女 2024-08-29 08:58:30

Perl 的 Text::Template 模块的作者 Mark-Jason Dominus 有一些见解这可能是相关的:

当人们制作模板模块时
就像这个,他们几乎总是
首先发明一种特殊的语法
用于替换。例如,他们
构建一个类似 %%VAR%% 的字符串
被替换为 $VAR 的值。
然后他们意识到需要额外的
格式化,所以他们放了一些
用于格式化的特殊语法。然后
他们需要一个循环,所以他们发明了一个
循环语法。很快他们就有了
新的小模板语言。

这种方法有两个问题:首先,
他们的小语言是残缺的。如果
你需要做一些事情,作者
没想到,你就输了。第二:
谁想学习另一种语言?

如果您编写自己的迷你语言,您可能最终会陷入同样的​​困境 - 为因设计而瘫痪的工具维护语法和解析器。

如果真正的编程语言看起来有点太低级,解决方案可能不是放弃该语言,而是为最终用户提供更高级别的实用功能,以便他们可以使用熟悉的概念进行操作,而不会陷入困境底层语言的杂草。

这使得初级用户能够进行高水平的操作;然而,您和任何有技巧的最终用户(您的超级用户)仍然可以充分利用 Ruby 或 Python 等的全部功能。

Mark-Jason Dominus, the author of Perl's Text::Template module, has some insights that might be relevant:

When people make a template module
like this one, they almost always
start by inventing a special syntax
for substitutions. For example, they
build it so that a string like %%VAR%%
is replaced with the value of $VAR.
Then they realize the need extra
formatting, so they put in some
special syntax for formatting. Then
they need a loop, so they invent a
loop syntax. Pretty soon they have a
new little template language.

This approach has two problems: First,
their little language is crippled. If
you need to do something the author
hasn't thought of, you lose. Second:
Who wants to learn another language?

If you write your own mini-language, you could end up in the same predicament -- maintaining a grammar and a parser for a tool that's crippled by design.

If a real programming language seems a bit too low-level, the solution may not be to abandon the language but instead to provide your end users with higher-level utility functions, so that they can operate with familiar concepts without getting bogged down in the weeds of the underlying language.

That allows beginning users to operate at a high level; however, you and any end users with a knack for it -- your super-users -- can still leverage the full power of Ruby or Python or whatever.

傲鸠 2024-08-29 08:58:30

听起来您可能需要为您的用户创建某种可以松散地构建在目标语言之上的领域特定语言 (DSL)。 Ruby、Python 和 Lua 在语法方面都有各种怪癖,在某种程度上,其中一些怪癖可以通过巧妙的函数定义来解决。

相当强大的 DSL 的一个例子是 Cucumber,它实现了一个有趣的策略,将用户指定的措辞转换为实际的可执行代码通过应用于输入数据的一系列正则表达式。

另一个候选者可能是 JavaScript,或者某种 DSL 到 JavaScript 的桥接器,因为这将允许策略运行客户端或服务器端。这可能有助于扩展您的应用程序,因为与负载较重的服务器相比,客户端计算机通常具有过剩的计算能力。

It sounds like you might need to create some sort of Domain Specific Language (DSL) for your users that could be built loosely on top of the target language. Ruby, Python and Lua all have their various quirks regarding syntax, and to a degree some of these can be massaged with clever function definitions.

An example of a fairly robust DSL is Cucumber which implements a an interesting strategy of converting user-specified verbiage to actual executable code through a series of regular expressions applied to the input data.

Another candidate might be JavaScript, or some kind of DSL to JavaScript bridge, as that would allow the strategy to run either client-side or server-side. That might help scale your application since client machines often have surplus computing power compared to a heavily loaded server.

若沐 2024-08-29 08:58:30

无论您选择什么,都将需要定制模块来定义您公司的高级结构。

以下是我设想的一些需求 - 您可能已经涵盖了其中一些需求:一种将当前头寸、当前和历史报价、以前的绩效数据等获取到应用程序中的方法。定义/回测/发送各种类型的订单(限价/市价/止损,什么交易所,触发)或期权参数等...您可能需要多个沙箱来进行测试以及真实的沙箱。

宽客希望能够进行矩阵运算、随机微积分、偏微分方程。
如果您想在 python 中执行此操作,加载 NumPy 将是一个开始。

您还可以从专为进行数学金融研究而设计的专有系统开始,例如基于 Mathematica 或 Matlab 构建的系统。

Custom-made modules are going to be needed, no matter what you choose, that define your firm's high level constructs.

Here are some of the needs I envision -- you may have some of these covered already: a way to get current positions, current and historical quotes, previous performance data, etc... into the application. Define/backtest/send various kinds of orders (limit/market/stop, what exchange, triggers) or parameters of options, etc... You probably are going to need multiple sandboxes for testing as well as the real thing.

Quants want to be able to do matrix operations, stochastic calculus, PDEs.
If you wanted to do it in python, loading NumPy would be a start.

You could also start with a proprietary system designed to do mathematical financial research such as something built on top of Mathematica or Matlab.

黑凤梨 2024-08-29 08:58:30

我一直在研究Python算法交易库(实际上是为了回溯测试,而不是为了真实交易)。您可能想看一下:http://gbeced.github.com/pyalgotrade/

I've been working on a Python Algorithmic Trading Library (actually for backtesting, not for real trading). You may want to take a look at it: http://gbeced.github.com/pyalgotrade/

花心好男孩 2024-08-29 08:58:30

查看 http://www.tadeveloper.com,了解使用 MATLAB 作为脚本语言的回溯测试框架。 MATLAB 的优点是它非常强大,但您不需要成为程序员即可使用它。

Check out http://www.tadeveloper.com for a backtesting framework using MATLAB as a scripting language. MATLAB has the advantage that it is very powerful but you do not need to be a programmer to use it.

深海夜未眠 2024-08-29 08:58:30

这可能有点简单,但很多量化用户都习惯使用 Excel 和 Excel。 VBA 宏。像 VBSCript 这样的东西可以使用吗,因为他们可能在这方面有一些经验。

This might be a bit simplistic, but a lot of quant users are used to working with Excel & VBA macros. Would something like VBSCript be usable, as they may have some experience in this area.

深爱成瘾 2024-08-29 08:58:30

现有语言“对于我的目标用户来说有点‘低级’”。

然而,您所需要的只是“对循环、简单算术、逻辑表达式评估的最低支持”,

我不明白这个问题。您只需要一些功能。您提供的语言列表有什么问题?他们实际上提供这些功能吗?

脱节是什么?请随时更新您的问题以扩展问题所在。

Existing languages are "a little "low level" for my target users."

Yet, all you need is "a minimum of support for looping, simple arithmatic, logical expression evaluation"

I don't get the problem. You only want a few features. What's wrong with the list of languages you provided? They actually offer those features?

What's the disconnect? Feel free to update your question to expand on what the problem is.

一曲琵琶半遮面シ 2024-08-29 08:58:30

我会使用 Common Lisp,它支持快速开发(您有一个正在运行的映像,可以编译/重新编译单个函数)并根据您的领域定制语言。您将提供函数和宏作为表达策略的构建块,并且整个语言将可供用户用于组合这些。

I would use Common Lisp, which supports rapid development (you have a running image and can compile/recompile individual functions) and tailoring the language to your domain. You would provide functions and macros as building blocks to express strategies, and the whole language would be available to the user for combining these.

戒ㄋ 2024-08-29 08:58:30

是否符合处理您所追求的复杂程度?处理是一个很好的例子,它采用成熟的语言(Java)并将可用语法减少/简化为仅适用于问题域的子集(问题域=处理情况下的可视化)。

这是处理文档中的一些并排比较。

Java:

g.setColor(Color.black)
fillRect(0, 0, size.width, size.height);

处理:

background(0);

正如其他人所建议的,您也许可以简单地编写足够的高级函数,以便对用户隐藏大部分复杂性,但您仍然保留在必要时执行更多低级操作的能力。 Arduino 的接线语言遵循在 C 之上使用薄层高级函数的策略为了让非程序员和业余爱好者更容易使用它。

Is something along the lines of Processing the complexity level that you're shooting for? Processing is a good example of taking a full-blown language (Java) and reducing/simplifying the available syntax into only a subset applicable to the problem domain (problem domain = visualization in the case of Processing).

Here's a little side-by-side comparison from the Processing docs.

Java:

g.setColor(Color.black)
fillRect(0, 0, size.width, size.height);

Processing:

background(0);

As others have suggested, you may be able to simply write enough high-level functions such that most of the complexity is hidden from the user but you still retain the ability to do more low-level things when necessary. The Wiring language for Arduino follows this strategy of using a thin layer of high-level functions on top of C in order to make it more accessible to non-programmers and hobbyists.

故事灯 2024-08-29 08:58:30

首先定义语言——如果可能的话,使用称为 EBN 的伪语言,它非常简单(参见维基百科条目)。

一旦你有了它,就选择语言。几乎可以肯定您会想要使用 DSL。在我看来,Ruby 和 Lua 都非常擅长这一点。

一旦你开始研究它,你可能会发现你回到了你的定义并对其进行了调整。但我认为这是正确的做事顺序。

Define the language first -- if possible, use the pseudo-language called EBN, it's very simple (see the Wikipedia entry).

Then once you have that, pick the language. Almost certainly you will want to use a DSL. Ruby and Lua are both really good at that, IMO.

Once you start working on it, you may find that you go back to your definition and tweak it. But that's the right order to do things, I think.

偏闹i 2024-08-29 08:58:30

我一直在用自己的软件建造和交易同一条船。 Java 并不是很好,因为你想要更高层次的东西,就像你说的那样。我使用 eclipse 项目 xtext 取得了很大的成功。 http://www.eclipse.org/Xtext 它为您完成构建解析器等的所有工作使用 Eclipse,您可以使用功能编辑器快速生成代码。我建议您在考虑其他选择的同时也考虑一下这一点。这与 eclipse 建模框架相结合对于快速构建听起来像您需要的 DSL 非常强大。 - 邓肯

I have been in the same boat building and trading with my own software. Java is not great because you want something higher level like you say. I have had a lot of success using the eclipse project xtext. http://www.eclipse.org/Xtext It does all the plumbing of building parsers etc. for you and using eclipse you can quickly generate code with functional editors. I suggest looking into this as you consider other options as well. This combined with the eclipse modeling framework is very powerful for quickly building DSL's which sounds like you need. - Duncan

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文