简体   繁体   English

ctrl shift输入数组

[英]ctrl shift enter for array

I'm trying to create a macro that returns the estimated std dev for a portfolio to a cell. 我正在尝试创建一个宏,将组合的估计std dev返回给单元格。 However, as the no of shares, their covar as well as their weights will change basically constantly and with the different portfolios i want this in VBA (my ultimate goal is to make my reporting as easy as possible). 然而,作为股票的一部分,他们的covar以及他们的权重将基本上不断变化,并且我想在VBA中使用不同的投资组合(我的最终目标是使我的报告尽可能简单)。

I can't seem to understand the ctrl + shift + enter , or the sqr part. 我似乎无法理解ctrl + shift + enter或sqr部分。

Could you please look at my code help me? 你能看一下我的代码帮帮我吗?

Sub PorteføljeRisiko()
Dim RapportBok As Workbook
Dim RapportArk As Worksheet
Set RapportBok = Workbooks("Rapport kunder")
Set RapportArk = RapportBok.Sheets(1)

Dim Region1 As Long
Dim RegionA As Long
Dim Matrise As Range

(as the no of shares vary, I here find out how many rows that actually include a value(ie % weighting in each share)) (由于股票的数量不同,我在这里找出实际包含一个值的行数(即每股的权重%))

Region1 = Application.WorksheetFunction.CountIf(RapportArk.Range("AC7:AC18"), "<>" & "")
RegionA = Region1 - 1 

(to get the matrix for the covar between shares as the no of shares change with puchase and sale of shares. the matrix starts in cells(3,55) (获得股票之间的covar矩阵,因为股票的变化与购买和出售股票一起变化。矩阵从单元格开始(3,55)

SisteKolonne = RapportArk.Cells(RegionA + 3, RegionA + 55)

Set Matrise = RapportArk.Range(Cells(3, 55), Cells(3 + RegionA, 55 + RegionA))

Set Region = RapportArk.Range("AC7:AC" & Region1 + 6)

(I want the result in Range("AG21")) (我希望结果在Range(“AG21”))

RapportArk.Range("AG21").FormulaArray = MMult(Application.MMult(Region, Matrise), Application.Transpose(Region))

(Everything works fine, except that it returns #VALUE! as i can't seem to get neither the ctrl + shift + enter part nor the SQR part in the macro) (一切正常,除了它返回#VALUE!因为我似乎既没有得到ctrl + shift + 输入部分也没有得到宏中的SQR部分)

End Sub

First of all what you are computing here in VBA is not a formula but a value . 首先,你在VBA中计算的不是formula而是value Apart of that, I could not verify all your calculations but I could see a problem here: 除此之外,我无法验证您的所有计算,但我可以在这里看到一个问题:

Application.MMult(Region, Matrise)

The dimensions do not respect the rules of matrix multiplication. 尺寸不符合矩阵乘法的规则。 From analyzing your code, Region is a column vector with size Region1 , while Matrise is a Region1 x Region1 Matrix. 通过分析代码, Region是一个大小为Region1的列向量,而Matrise是一个Region1 x Region1 Matrix。

Remember that Matrix multiplication is not commutative. 请记住,矩阵乘法不是可交换的。 Most likely what you wanted is to switch the order of these operands: 您最想要的是切换这些操作数的顺序:

Application.MMult(Matrise, Region)

This will give you a column vector of size Region1 . 这将为您提供大小为Region1的列向量。 But then you want to have a dot product with the vector Region and here again, the row vector should come first, so you should apply the Transpose on the first operand not on the second one. 但是你想要一个带有矢量Region的点积,再次, 行矢量应该先行,所以你应该在第一个操作数上应用Transpose ,而不是在第二个操作数上。 So the correct statement should be: 所以正确的陈述应该是:

RapportArk.Range("AG21").value = _
    Application.MMult(Application.Transpose(Application.MMult(Matrise, Region)), Region)

Since the last operation is the dot-product of two vectors, you can probably simplify it using SumProduct : 由于最后一个操作是两个向量的dot-product ,您可以使用SumProduct简化它:

RapportArk.Range("AG21").value = _
    Application.SumProduct(Application.MMult(Matrise, Region), Region)

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

相关问题 获取Excel插件以修改数组公式参数; 或执行“ ctrl-shift-enter” - Getting Excel add ins to modify array formula parameters; or perform 'ctrl-shift-enter' Excel VBA Ctrl-Shift-Enter 数组 function 与编写长工作表相比非常慢 - Excel VBA Ctrl-Shift-Enter array function very slow compared to writing long worksheet function 您是否可以在不按Ctrl + Shift + Enter的情况下向下复制数组公式? - Can you copy array formula down without having to hit Ctrl+Shift+Enter? Excel VBA-用户定义函数-将与数组相关的公式(常规公式上为CTRL + SHIFT + ENTER)转换为UDF - Excel VBA - User Defined Function - converting array related formula (CTRL + SHIFT + ENTER on a normal formula) to a UDF 如何在excel范围内显示1或2 dim varraint array()返回excel UDF函数而不使用Ctrl + Shift + Enter数组论坛方法 - How to display a 1 or 2 dim varraint array() return from an excel UDF function in an excel range without Ctrl+Shift+Enter array forumla method 数组中用于array_shift的数组 - Array in array for array_shift 按索引移动数组中的元素 - Shift elements in array by index Java数组移位引用 - Java array shift referencing 移动数组中元素的位置 - Shift the position of an element in an array Scala:移位数组中的元素 - Scala: Shift elements in an Array
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM