# SDT Shared Variables: Fixed Memory That Saves Resources and Lets Instruments in the Same Strategy Pass Data to Each Other

- Channel: 量化交易科學園區 - 江加宏
- Published: 2026-10-28
- Series: [Quant Trading Science Park](https://xknow.app/en/s/quant-trading-science-park/?ref=agent) ([series index](https://xknow.app/en/s/quant-trading-science-park/llms.txt))
- Topics: [AI & Software Engineering](https://xknow.app/en/topics/ai-engineering/llms.txt)
- Page: https://xknow.app/en/v/quant-trading-science-park-ep4/?ref=agent
- YouTube: https://www.youtube.com/watch?v=DNy3fdbcGSY

> SDT shared variables take up a fixed amount of memory no matter how many candlesticks there are, which saves resources, improves execution efficiency, and lets instruments in the same strategy pass data to each other; the cost is that you cannot read past values and cannot backtest.

## Key ideas

- Ordinary variables are serialized, so every candlestick needs another slice of memory; SDT just keeps overwriting the fixed positions you declared. In a test with 8 moving-average lines, ordinary variables used 2.5G more and were not fully released after stopping, while SDT used only a bit more than 1G, a large part of which was the candlestick data itself.
- The cost of SDT is that you cannot use square brackets to get past values, but most cases can be solved with math; the other limitation is that it cannot be backtested. If you do not care about memory and need backtesting or past values, traditional variables are actually better.
- Usage is like an Excel sheet in memory: row names and column names act as coordinates, you store values with SetValue and read them with GetValue; it is recommended to use text for all coordinates, and to add a default value of 0 when reading so the program does not crash if nothing is found. The table is drawn in memory only as far as it is used, not filled up front.
- After adding L to a function, all stocks monitored by the same strategy share one table, which is what lets stocks communicate with each other. Practical uses include calculating the market index moving average only once, checking in pairs arbitrage whether the other leg has been filled, and ranking intraday real-time PR values; the cross-strategy version has not been released yet.

## Section summaries

### 0:05 SDT Variables Take Up Just 5 Memory Slots

No matter how many candlesticks the program runs, SDT takes up only a fixed 5 memory slots, in contrast to ordinary variables, which use more memory as candlesticks increase. The instructor gives the example of storing stock codes and price changes, then ranking them intraday to compute PR values, to show that SDT's first benefit is better execution efficiency.

[Page](https://xknow.app/en/v/quant-trading-science-park-ep4/?ref=agent#s-0) | [YouTube 0:05](https://www.youtube.com/watch?v=DNy3fdbcGSY&t=5s)

### 0:55 SDT's Second Benefit: Passing Data Across Instruments

SDT's second benefit is that it lets different instruments pass data to each other, which the instructor says will be explained later; but first you need to understand that SDT is essentially a kind of variable, so the talk starts with ordinary variables.

[Page](https://xknow.app/en/v/quant-trading-science-park-ep4/?ref=agent#s-1) | [YouTube 0:55](https://www.youtube.com/watch?v=DNy3fdbcGSY&t=55s)

### 1:15 Trade-offs Between Ordinary Variables and SDT

An ordinary variable is like a container: the more candlesticks, the more memory it takes. SDT uses only the fixed slots you declared and does not grow with candlesticks. The cost is that you cannot use square brackets to get past values, but 90% of cases can be solved with math.

[Page](https://xknow.app/en/v/quant-trading-science-park-ep4/?ref=agent#s-2) | [YouTube 1:15](https://www.youtube.com/watch?v=DNy3fdbcGSY&t=75s)

### 10:55 Adding L to a Function Lets Stocks Share Data

Adding L after the function name means that SDT memory position belongs not to a single stock but can be used by all stocks monitored by the same strategy, so stocks can communicate with each other. Currently only 2 kinds are available: a single stock's own variables, and sharing across stocks within the same strategy; the cross-strategy G version has not been released.

[Page](https://xknow.app/en/v/quant-trading-science-park-ep4/?ref=agent#s-3) | [YouTube 10:55](https://www.youtube.com/watch?v=DNy3fdbcGSY&t=655s)

### 14:45 Memory Test Comparing 8 Moving-Average Variables

In a test of a program that only writes 8 moving-average variables: ordinary variables raised memory from 3.4G to 5.9G, using 2.5G more, and after the program was stopped it was still at 5.6G, so it was not fully released; with SDT, memory rose from about 4.5G to 5.5G, only a bit more than 1G, a large part of which was the candlestick data itself, and the system also ran more smoothly.

[Page](https://xknow.app/en/v/quant-trading-science-park-ep4/?ref=agent#s-4) | [YouTube 14:45](https://www.youtube.com/watch?v=DNy3fdbcGSY&t=885s)

### 18:55 SDT Is Like an Excel Sheet in Memory

SDT is like an Excel sheet in memory, with up to 5000 rows and 100 columns. Row names must be text, while column names can be names or the column number, but using text for all is strongly recommended. Use SDT_SetValue to store values and SDT_GetValue to read them; add a default value of 0 when reading, so that if nothing is found it returns 0 and the program does not crash.

[Page](https://xknow.app/en/v/quant-trading-science-park-ep4/?ref=agent#s-5) | [YouTube 18:55](https://www.youtube.com/watch?v=DNy3fdbcGSY&t=1135s)

### 26:15 Single-Instrument Use: Optimizing Efficiency and Saving Resources

SDT's first use is to optimize program efficiency and save resources for a single instrument; since it does not have to handle large amounts of data, it runs a bit faster. The limitation is that you cannot use square brackets to get past values, but more than 90% of cases can be solved by calculation. The talk then turns to cross-instrument applications within the same strategy.

[Page](https://xknow.app/en/v/quant-trading-science-park-ep4/?ref=agent#s-6) | [YouTube 26:15](https://www.youtube.com/watch?v=DNy3fdbcGSY&t=1575s)

### 27:45 Demonstration of Sharing Data Across Instruments

The demonstration uses SDT_SetValue_L to share data across instruments: the market index moving average is calculated once by one stock and the other stocks simply read it; in pairs arbitrage, it checks whether the other instrument has been filled; and it ranks real-time PR values intraday. You can also read a file at startup and write back every 10 seconds to continue calculations such as OBV. However, SDT cannot be backtested, and cross-strategy is not yet supported.

[Page](https://xknow.app/en/v/quant-trading-science-park-ep4/?ref=agent#s-7) | [YouTube 27:45](https://www.youtube.com/watch?v=DNy3fdbcGSY&t=1665s)

---

Full notes (with slides) and other episodes in this series: https://xknow.app/en/v/quant-trading-science-park-ep4/?ref=agent

Watch the original video: https://www.youtube.com/watch?v=DNy3fdbcGSY
